Skip to content

[PG-01] Add bounded durable counter maintenance - #9

Merged
FlyOverCoderKY merged 3 commits into
mainfrom
codex/pg01-bounded-maintenance
Nov 8, 2026
Merged

FlyOverCoderKY merged 3 commits into
mainfrom
codex/pg01-bounded-maintenance

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Hosts need to remove expired durable counters within a fixed maintenance budget. Add sweepDurableWindowsPage, which scans one physical page, returns the adapter continuation, and conditionally deletes only expired windows that match their actual storage key and current policy descriptor.

This is the PG-01 prerequisite for scheduled Knowledge Base and Agent Access cleanup. Existing limiter admission, memory behavior, and per-policy sweep stay unchanged. Unknown legacy rows remain; hosts must deliberately migrate them. The candidate is 0.3.0 because current main also contains descriptor and clock-skew hardening absent from published 0.2.0. Host adoption and publication follow separately.

Validation: formatting, types, release metadata, all 110 tests across Memory and real Azurite, and a clean packed-artifact consumer passed. An independent static review found no concrete issue. CI must repeat the gates on Node 22 and 24. Final merge also requires current-head code/security review and both complete OpenRouter review lanes.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

OpenRouter review posted (clean). #9 (review)

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T16:10:41.837289Z 9e852b4 Manual request
🔒 Security Review ✅ Completed 2026-11-08T16:12:56.164535Z 9e852b4 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: f82b925d82

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: f82b925d82

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenRouter pull-request review

Verdict: issues
Scope: full-pr (full-pr)
Mode: initial
Commit: f82b925d827a2658bcbc7e0d83e71e4f1cd49ddb
Judge: openai/gpt-5.6-luna
Cost: $0.1918 (lanes $0.1889 + judge $0.0029)

Lanes

  • openai/gpt-6.1-sol: ok (1 finding(s), 52.5s, 158411+2120 tokens (118092 cached), 5 tool round(s), via Azure, $0.15)
  • z-ai/glm-5.3-flash: ok (4 finding(s), 423.3s, 1009972+33199 tokens (943616 cached), 23 tool round(s), via Wafer, $0.0417)

Warning

z-ai/glm-5.3-flash: coverage claims 4 finding(s) in 'packages/rate-limit/src/durable.ts' but 3 were reported

Findings

🔵 Issue 1 — Per-page maintenance budget assertions

packages/rate-limit/src/durable-sweep-page.test.ts:185 · nit · identified by openai/gpt-6.1-sol

A regression that performs multiple scans or extra descriptor reads on a limit: 1 call could pass the pagination test while exceeding the host's per-call maintenance budget.

The test checks that every scan requests 1, but not that each helper call makes exactly one scan. It also compares descriptor reads against the total rows scanned across the complete cycle, allowing unused budget from descriptor, legacy, and malformed-row pages to hide excess work on an expired-window page. Capture the instrumentation counters before each call and assert per-call deltas: exactly one scan, at most limit descriptor reads, and at most limit conditional deletes.

The current implementation respects these bounds. I also checked the oversized-page test and the exact descriptor-read assertions in the later tests; those cover other scenarios but do not enforce the operation budget on each continuation call with limit: 1.

🟠 Issue 2 — A page is bounded in rows and storage calls but not in wall-clock time, and a mid-page failure forces a full page redo

packages/rate-limit/src/durable.ts:555 · risk · identified by z-ai/glm-5.3-flash

A host that sizes limit near the documented maximum of 1,000 for throughput can get a single call that runs for tens of seconds to minutes. The loop processes rows strictly sequentially with one awaited getVersioned plus one awaited deleteIfUnchanged per expired candidate, so a page of 1,000 expired windows is up to ~2,000 sequential storage round trips (at 20–50 ms per call on a shared store, roughly 40–100 s inside one invocation). The PR and READMEs market this as a "fixed maintenance budget", but the budget bounds physical rows and call counts only — there is no deadline option, no concurrency, and no partial-progress reporting.

The failure interaction makes this worse: on any mid-page storage error the helper rejects with no nextCursor, and the documented contract tells the host to retain the previous cursor and retry. The retry then re-runs the whole page from its start, re-paying up to limit descriptor reads and deletes for work that was already partially done, repeatedly, if the store is flaky near the end of large pages.

What I checked: the loop in sweepDurableWindowsPage (durable.ts lines ~567–603) does one descriptor read and one conditional delete per row with no batching or parallelism; the docs (root README "Bounded global durable maintenance", package README "Bounded global cleanup", PROJECT_PLAN "0.3.0 candidate") consistently describe the bound as rows/calls and never mention a time bound, so this is a genuine unspecified dimension of the "budget", not a doc/code mismatch. The existing per-policy sweep() has the same shape but is partition-scoped and typically tiny, so the exposure is new with the global page API. Proof gap: I cannot measure real adapter latency from this checkout; the scenario cost depends on the host's storage, but the absence of any time bound or progress-on-failure mechanism is verifiable in the code.

🔵 Issue 3 — Dead defensive guards: row.value can never be null or a non-object after the spread copy

packages/rate-limit/src/durable.ts:570 · nit · identified by z-ai/glm-5.3-flash

if (row.value === null || typeof row.value !== "object") continue; can never trigger. Two lines earlier, rows is built with value: { ...row.value }, and spreading null, undefined, a string, or a number in JS always produces a plain non-null object ({ ...null } is {}). The actual filtering is done by validWindow(row.value) on the next line.

The cost is reader/maintainer confusion in exactly the code path whose safety reviewers must verify: it suggests null-valued scan rows are deliberately handled here when they are not (they become {} and are skipped only because validWindow rejects a null kind). A future edit that replaces the spread with a direct reference would silently change what this guard does.

Checked against the whole helper: every other field access in the loop (row.key.partition, descriptor.value.kind via descriptorMatches) dereferences without an equivalent guard, which reinforces that this one is vestigial rather than a deliberate contract.

🔵 Issue 4 — Malformed scan-row keys or descriptor values crash the whole page with a generic TypeError, contradicting the retain-malformed-rows posture

packages/rate-limit/src/durable.ts:566 · nit · identified by z-ai/glm-5.3-flash

The helper's stated posture (READMEs and JSDoc) is that malformed rows are retained, not fatal: "Descriptors, legacy 0.2.0 rows, malformed rows, and policy mismatches remain stored." But that tolerance stops at the record envelope: page.records.map((row) => ({ key: { partition: row.key.partition, id: row.key.id }, ... })) dereferences row.key (and row itself) with no guard, and descriptorMatches(descriptor.value, ...) dereferences descriptor.value.kind with no guard.

Concrete scenario: an adapter (or a future storage-core version) returns a scan row with a null/absent key, or a getVersioned hit with a null value. The helper then throws a generic TypeError: Cannot read properties of null (reading 'partition') — after possibly having already deleted earlier candidates in the page — instead of skipping/retaining the malformed row like every other kind of malformed state. The page-level contract "storage failures reject" arguably covers it, but the failure is a coding crash, not a storage failure, and it is inconsistent with the care taken one line below for row.version (typeof row.version !== "string") and for every payload field in validWindow.

Counterevidence I checked: no conforming path in this repo produces such rows — the memory-store and Azurite tests always yield keyed rows — so this is only reachable via a non-conforming adapter; I kept it because the entire helper exists to be paranoid about adapter-returned state and already validates page.records being an array and nextCursor's shape.

🔵 Issue 5 — Tests do not pin the per-page descriptor-read budget, and cursor input validation is untested

packages/rate-limit/src/durable-sweep-page.test.ts:203 · nit · identified by z-ai/glm-5.3-flash

The headline budget guarantee — "at most limit fresh descriptor reads and limit deleteIfUnchanged calls" per page (root README, package README, PROJECT_PLAN, and the JSDoc) — is only weakly pinned. The assertions are cumulative and one-sided: expect(track.gets()).toBeLessThanOrEqual(scanned) (line 203 and line 282) bounds total gets by total rows across the whole cycle, not by limit per page. A regression that reads the descriptor twice per candidate (or once before and once after the delete attempt) yields gets = 2 × candidates, which still passes whenever candidates are a minority of scanned rows — exactly the situation in both tests that use the assertion (2 candidates out of 9 scanned; 0 candidates out of 9). Only deletes() is asserted exactly.

Additionally, the runtime validation of cursor (empty string, non-string, added in this PR at durable.ts lines ~541–547) has no test at all, while the sibling validations for limit, maxClockSkewMs, and the clock each have dedicated it.each cases in "bounded cleanup input failures". A refactor that drops or weakens the cursor check would not fail any test.

What I checked: all 440 lines of the new test file; the observed wrapper records every scan/getVersioned/deleteIfUnchanged, so a per-page assertion like gets() <= scanned per individual call result (or gets() <= result.scanned accumulated per page against that page's limit) would be cheap to add and would make the documented budget falsifiable.

Workflow run

Comment thread packages/rate-limit/src/durable.ts Resolved
Comment thread packages/rate-limit/src/durable.ts Resolved
Comment thread packages/rate-limit/src/durable.ts Resolved
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d8bb1ffc71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenRouter pull-request review

Verdict: issues
Scope: latest-commit (commit-range)
Mode: verify
Commit: d8bb1ffc7141f4da77f4c3e941f44deb3fcdf6ae
Judge: openai/gpt-5.6-luna
Cost: $0.0709 (lanes $0.0700 + judge $0.0009)

Lanes

  • openai/gpt-6.1-sol: ok (0 finding(s), 17.8s, 43979+706 tokens (26598 cached), 3 tool round(s), via Azure, $0.0585)
  • z-ai/glm-5.3-flash: ok (1 finding(s), 55.6s, 87450+8378 tokens (48384 cached), 5 tool round(s), via DeepInfra, $0.0115)

Round 2 resolution

  • ✅ r1-2 fixed correctly — A page is bounded in rows and storage calls but not in wall-clock time, and a mid-page failure forces a full page redo: The root README, package README, and project plan now explicitly define the budget as physical-row and storage-call bounds, state that operations are sequential with no wall-clock or deadline guarantee, and advise hosts to choose small limits based on provider latency and execution/subrequest budgets. They also explain that mid-page failures preserve earlier deletions and retries can repeat work.
    …
  • 4 nit finding(s) from earlier rounds retired (severity floor for follow-up rounds is risk).
  • Open findings after this round: 1 (0 bug-severity).

Findings

🟠 Issue 1 — README overclaims row-envelope rejection that the sweep does not perform

packages/rate-limit/README.md:146 · risk · identified by z-ai/glm-5.3-flash

The new sentence "A nonconforming adapter page/row envelope rejects instead of being treated as a malformed stored payload to skip" does not match the implementation for row-level envelopes.

In sweepDurableWindowsPage the only runtime envelope validation is page-level (durable.ts:565-571: records is an array, length <= limit, nextCursor is a nonempty string or null). Row-level nonconformance is skipped, not rejected:

  • a row whose value is null/non-object is spread into {} and dropped by validWindow -> continue (this is exactly the old skip behavior; the removed guard in this commit's durable.ts hunk did not change it),
  • a row with a non-string or empty version hits typeof row.version !== "string" ... -> continue at durable.ts:583-584, i.e. treated as a malformed payload to skip,
  • a row missing key only fails via an incidental TypeError on row.key.partition at durable.ts:572 — mid-loop, after earlier candidates may already have issued descriptor reads and conditional deletes, which also contradicts the companion claim that "Physical page validation runs before descriptor reads or deletes".

So the same commit documents a reject-not-skip guarantee for row envelopes that the code does not implement, and a validation-before-keyed-work ordering that a malformed row key breaks. Only the page-level envelope (which the tests cover via the oversized hook) actually behaves as documented.

Either implement row-envelope validation up front (verify each row's key.partition/key.id/version/value shape and reject the call before any descriptor read), or narrow the README/root-README/PROJECT_PLAN wording to the page-level envelope that is actually validated. I could not run the tests in this environment; the finding is based on direct reading of durable.ts:551-604 and the store wrapper in durable-sweep-page.test.ts:107-124, and I found no code path that validates individual rows before the candidate loop.

Workflow run

Comment thread packages/rate-limit/README.md Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: d8bb1ffc71

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 9e852b47d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenRouter pull-request review

Verdict: clean
Scope: latest-commit (commit-range)
Mode: verify
Commit: 9e852b47d30d6089352a6d3e06d389e4ee9865f7
Judge: openai/gpt-5.6-luna
Cost: $0.0757 (lanes $0.0755 + judge $0.0001)

Lanes

  • openai/gpt-6.1-sol: ok (0 finding(s), 15.5s, 45937+687 tokens (29771 cached), 3 tool round(s), via Azure, $0.0553)
  • z-ai/glm-5.3-flash: ok (0 finding(s), 89.9s, 166862+16415 tokens (103168 cached), 5 tool round(s), via Modal, $0.0203)

Round 3 resolution

  • ✅ r2-1 fixed correctly — README overclaims row-envelope rejection that the sweep does not perform: sweepDurableWindowsPage now validates all returned row envelopes before descriptor reads or deletes, rejecting invalid rows, keys, versions, and null/array/primitive values rather than silently skipping them. Malformed object payloads still pass through to the existing structural checks and are retained, matching the README's distinction.

The added tests cover corruption of the final row and as…

  • Open findings after this round: 0 (0 bug-severity).

No structured findings from the successful lane(s).

Workflow run

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9e852b47d3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenRouter pull-request review

Verdict: clean
Scope: full-pr (full-pr)
Mode: verify
Commit: 9e852b47d30d6089352a6d3e06d389e4ee9865f7
Judge: openai/gpt-5.6-luna
Cost: $0.2108 (lanes $0.2106 + judge $0.0001)

Lanes

  • openai/gpt-6.1-sol: ok (0 finding(s), 30.9s, 227134+1121 tokens (174614 cached), 5 tool round(s), via Azure, $0.18)
  • z-ai/glm-5.3-flash: ok (0 finding(s), 635.3s, 1029978+26743 tokens (954432 cached), 22 tool round(s), via Relace, $0.0347)

Round 4 resolution

  • No prior findings were open.
  • Open findings after this round: 0 (0 bug-severity).

No structured findings from the successful lane(s).

Workflow run

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

Exact-head merge gate for 9e852b4: Node22/24 each passed138 tests across4 files, zero skips, plus formatting/types/release metadata. Independent source review and packed-artifact consumer passed. Current-head Codex code/security receipts are clean. Full-PR OpenRouter run42498783521 reviewed all7 paths/41439bytes; both lanes successful, unsalvaged, complete costs; canonical review5818643186 has0 OPEN. The retained artifact does not expose raw provider finish reasons or recovered tool transcripts; no claim is made about those unobservable fields. All review threads are resolved. Copilot was requested for this head during16:09:46.4400312Z–16:09:47.1410113Z; all-page issue/review/inline audit at16:40:18Z found no Copilot activity after more than30minutes. Copilot remains unavailable, not passed; proceeding under the documented bounded-wait fallback, with no inferred cause. Normal exact-head squash merge only; publication and host adoption remain separate gates.

@FlyOverCoderKY
FlyOverCoderKY merged commit 93c7a42 into main Nov 8, 2026
6 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the codex/pg01-bounded-maintenance branch November 8, 2026 16:40
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.

1 participant