Skip to content

postgres_integer_overflow_primary_key problem (astronomy-shop) - #1005

Merged
Saadmrp1038 merged 25 commits into
SREGym:mainfrom
saihariG:problem/integer-overflow-primary-key-astronomy-shop
Sep 18, 2026
Merged

Saadmrp1038 merged 25 commits into
SREGym:mainfrom
saihariG:problem/integer-overflow-primary-key-astronomy-shop

Conversation

@saihariG

@saihariG saihariG commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements #971

1. Real-world Failure Story

An INTEGER (int4) primary key or identity sequence has a hard ceiling of 2,147,483,647. On a high-write table the sequence eventually exhausts, and every new INSERT that allocates an id via nextval() begins failing with reached maximum value of sequence, while existing reads keep working, the classic "database is up but half-broken" outage that fools responders looking at pod/CPU health.

Relevant PostgreSQL behavior is documented under numeric types and sequence functions.

2. Simulation on SREGym

App: astronomy-shop
The product-reviews service writes to reviews.productreviews, whose id is an INTEGER GENERATED BY DEFAULT AS IDENTITY column backed by reviews.productreviews_id_seq.

  • inject_fault(): pins the sequence at int4 max (setval(seq, 2147483647, true)) so the next nextval() overflows, then confirms that a write actually fails and raises if the fault did not take.
  • recover_fault(): applies the durable real-world fix, a schema migration widening the column and sequence to BIGINT (ALTER COLUMN id TYPE bigint + ALTER SEQUENCE ... AS bigint), then verifies writes succeed again.
  • Mitigation oracle: a rollback-wrapped INSERT probe (leaves no data) that accepts the fix only when a write succeeds. The default pod-health oracle cannot detect this since every pod stays Running.

3. Problem run-time behavior

  • New product-review writes fail with ERROR: nextval: reached maximum value of sequence "productreviews_id_seq" (2147483647).
  • Reads of existing reviews stay healthy; product-reviewsand postgresql pods stay Running with normal CPU and memory.
  • The cause is only visible inside the database (the id column's type and the sequence's last_value), not from pod health.
  • Naive fixes like restarting or scaling pods is NOT a valid mitigation.
Screenshot 2026-09-06 at 12 48 55 AM

Notes

  • Recovery uses the durable BIGINT migration (the real SRE fix). A sequence reset is only a safe band-aid when the id space is collision-free.
  • astronomy-shop is redeployed fresh each run, so the exhausted sequence never leaks across runs.
  • The write-probe deliberately triggers a failing INSERT to detect exhaustion, so an expected ERROR line appears in the validation log on the exhausted path.

/validate-problem integer_overflow_primary_key_astronomy_shop

@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Z.ai Problem Difficulty Evaluation

No result CSV was produced. Inspect the benchmark and cluster logs.

Workflow run

@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Problem Difficulty Evaluation

❌ Failed before a pass-rate report was produced.

Inspect the workflow run for the preflight or infrastructure error.

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Z.ai Problem Difficulty Evaluation

  • Problem: integer_overflow_primary_key_astronomy_shop
  • Model: glm-5.3-flash via the Codex harness
  • Requested attempts: 5
  • Complete attempts: 1
  • Diagnosis pass rate: 1/1 (100%)
  • Mitigation pass rate: 1/1 (100%)
  • Overall pass rate: 1/1 (100%)

Overall requires both diagnosis and mitigation to pass. Infrastructure-incomplete attempts are not counted as model failures.

Attempt Diagnosis Mitigation Overall Notes
1 — — ⚠️ agent exited before all stages completed at diagnosis
2 ❌ — ⚠️ agent exited before all stages completed at mitigation
3 ✅ ✅ ✅ —
4 — — ⚠️ agent timeout at diagnosis
5 — — ⚠️ agent exited before all stages completed at diagnosis

Screening decision

⚠️ Inconclusive — one or more requested attempts did not produce both stage results; rerun it.

Workflow run

@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Problem Difficulty Evaluation

No result CSV was produced. Inspect the benchmark and cluster logs.

Workflow run

@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Z.ai Problem Difficulty Evaluation

  • Problem: integer_overflow_primary_key_astronomy_shop
  • Model: glm-5.3-flash via the Codex harness
  • Requested attempts: 5
  • Complete attempts: 3
  • Diagnosis pass rate: 0/3 (0%)
  • Mitigation pass rate: 0/3 (0%)
  • Overall pass rate: 0/3 (0%)

Overall requires both diagnosis and mitigation to pass. Infrastructure-incomplete attempts are not counted as model failures.

Attempt Diagnosis Mitigation Overall Notes
1 — — ⚠️ agent timeout at diagnosis
2 ❌ ❌ ❌ —
3 ❌ ❌ ❌ —
4 — — ⚠️ agent timeout at diagnosis
5 ❌ ❌ ❌ —

Screening decision

⚠️ Inconclusive — one or more requested attempts did not produce both stage results; rerun it.

Workflow run

Comment thread sregym/conductor/problems/integer_overflow_primary_key_astronomy_shop.py Outdated
Comment thread sregym/conductor/oracles/integer_overflow_primary_key_mitigation.py Outdated
Comment thread sregym/conductor/oracles/integer_overflow_primary_key_mitigation.py Outdated
@HacksonClark

Copy link
Copy Markdown
Member

@saihariG please resolve @Saadmrp1038's comments and request another review.

@saihariG
saihariG requested a review from Saadmrp1038 September 9, 2026 05:24
@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Z.ai Problem Difficulty Evaluation

  • Problem: integer_overflow_primary_key_astronomy_shop
  • Model: glm-5.3-flash via the Codex harness
  • Requested attempts: 5
  • Complete attempts: 1
  • Diagnosis pass rate: 1/1 (100%)
  • Mitigation pass rate: 1/1 (100%)
  • Overall pass rate: 1/1 (100%)

Overall requires both diagnosis and mitigation to pass. Infrastructure-incomplete attempts are not counted as model failures.

Attempt Diagnosis Mitigation Overall Notes
1 — — ⚠️ agent timeout at diagnosis
2 ❌ — ⚠️ agent timeout at mitigation
3 ✅ ✅ ✅ —
4 ❌ — ⚠️ agent timeout at mitigation
5 — — ⚠️ agent exited before all stages completed at diagnosis

Screening decision

⚠️ Inconclusive — one or more requested attempts did not produce both stage results; rerun it.

Workflow run

@Saadmrp1038 Saadmrp1038 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saihariG Thanks for the updates! After some more testing I found some other issues.

Scenario Expected Actual
Add new reviews, then delete all 50 original reviews Fail: original data must survive Pass: the row count and sentinel checks do not detect the lost reviews
Repair the sequence but remove the application user’s INSERT permission Fail: application writes are still broken Pass: the root probe succeeds while the writer repeatedly reports permission errors
Remove the primary key without equivalent uniqueness protection Fail: review IDs must remain unique Pass: the database also accepts an INSERT with an existing ID
Reset the sequence toward occupied IDs Fail: the available range is not collision-free Pass: the active writer starts reporting duplicate-ID errors 29 seconds later
Use a descending sequence through unused negative IDs Pass: writes work and substantial unused capacity remains Fail: the headroom calculation assumes an ascending sequence
Rename the identity sequence after a correct BIGINT repair Pass: the identity column and writes still work Fail: the oracle looks for the old sequence name
Read the injected sentinel row No explicit fault or oracle labels The agent can read seq_overflow_sentinel and fault marker row; do not delete (just make it look like a normal review)

I think creating a foolproof mitigation oracle for this fault that guarantees all future writes will succeed indefinitely is not realistic. Fixing possible edge cases should be sufficient.

@saihariG

Copy link
Copy Markdown
Contributor Author

@saihariG Thanks for the updates! After some more testing I found some other issues.

Scenario Expected Actual
Add new reviews, then delete all 50 original reviews Fail: original data must survive Pass: the row count and sentinel checks do not detect the lost reviews
Repair the sequence but remove the application user’s INSERT permission Fail: application writes are still broken Pass: the root probe succeeds while the writer repeatedly reports permission errors
Remove the primary key without equivalent uniqueness protection Fail: review IDs must remain unique Pass: the database also accepts an INSERT with an existing ID
Reset the sequence toward occupied IDs Fail: the available range is not collision-free Pass: the active writer starts reporting duplicate-ID errors 29 seconds later
Use a descending sequence through unused negative IDs Pass: writes work and substantial unused capacity remains Fail: the headroom calculation assumes an ascending sequence
Rename the identity sequence after a correct BIGINT repair Pass: the identity column and writes still work Fail: the oracle looks for the old sequence name
Read the injected sentinel row No explicit fault or oracle labels The agent can read seq_overflow_sentinel and fault marker row; do not delete (just make it look like a normal review)
I think creating a foolproof mitigation oracle for this fault that guarantees all future writes will succeed indefinitely is not realistic. Fixing possible edge cases should be sufficient.

Thanks for the thorough testing @Saadmrp1038 ! I reworked the oracle and stress-tested covering all the scenarios.

  1. The write probe now runs as the application user
  2. The oracle captures the original reviews at fault injection and requires them to survive, so deleting the originals and padding with new rows is rejected.
  3. The oracle requires a single column PK/UNIQUE constraint on id to still exist
  4. Added a collision free check (the sequence must be positioned past every existing id), so a reset that collides on later inserts fail immediately until the writer collides
  5. Headroom is direction aware, so a descending sequence passes
  6. The sequence is resolved via pg_get_serial_sequence
  7. The marker row is an ordinary-looking review matched by content

Also I verified locally that all valid fixes still pass, and every cheat is rejected.

@HacksonClark

Copy link
Copy Markdown
Member

/evaluate-problem integer_overflow_primary_key_astronomy_shop

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

In response to this command.

Z.ai Problem Difficulty Evaluation

  • Problem: integer_overflow_primary_key_astronomy_shop
  • Model: glm-5.3-flash via the Codex harness
  • Requested attempts: 5
  • Complete attempts: 4
  • Diagnosis pass rate: 3/4 (75%)
  • Mitigation pass rate: 4/4 (100%)
  • Overall pass rate: 3/4 (75%)

Overall requires both diagnosis and mitigation to pass. Infrastructure-incomplete attempts are not counted as model failures.

Attempt Diagnosis Mitigation Overall Notes
1 — — ⚠️ agent exited before all stages completed at diagnosis
2 ✅ ✅ ✅ —
3 ✅ ✅ ✅ —
4 ❌ ✅ ❌ —
5 ✅ ✅ ✅ —

Screening decision

⚠️ Inconclusive — one or more requested attempts did not produce both stage results; rerun it.

Workflow run

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

LGTM.
Thanks for the work @saihariG

@Saadmrp1038
Saadmrp1038 merged commit 58e9cda into SREGym:main Sep 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants