Skip to content

test: rotation test key ids on PostgreSQL and test helper cleanup (issue #442) [codex] - #465

Draft
PetrefiedThunder wants to merge 1 commit into
claude/signing-key-retired-refusesfrom
codex/grok-bot/amw-b002-i442-x
Draft

PetrefiedThunder wants to merge 1 commit into
claude/signing-key-retired-refusesfrom
codex/grok-bot/amw-b002-i442-x

Conversation

@PetrefiedThunder

Copy link
Copy Markdown
Collaborator

Fixes #442

Draft PR from the AMW fleet cohort, job amw-b002-i442-x. Merges only after green CI and a PASS from a different engine; this repo deploys to production on merge, so it also waits for C.Lee's deploy yes.

Job brief and acceptance criteria

Job AMW-B002: test: rotation test key ids on PostgreSQL and test helper cleanup (issue #442)

Repo: agent-middleware
Area: gateway

Fix the two test only findings in issue #442 (follow up to #331): make the signing key rotation tests use key ids that work on PostgreSQL as well as SQLite, and clean up the shared test helper so it does not leak state between tests.

Acceptance criteria: Tests pass on SQLite locally and are written to be PostgreSQL safe (no SQLite only assumptions); no product code changes; PR body says 'Fixes #442'.

Implementer report (codex)

Implemented both fixes, with no product code changes:

Both files overlap open PRs.

Validation: 135 gateway tests, 485 SDK tests, and 96 verifier vectors passed. Ruff, mypy, secret scanning, and SDK build passed. All seven regression cases failed before the fixes. PostgreSQL execution and the full gateway suite remain unverified.

Exact commands, results, and follow ups

Uncommitted: sandbox permissions blocked Git’s index.lock. Operator commit required. Nothing pushed; no PR opened. Future PR body must include Fixes #442.

Branch: codex/grok-bot/amw-b002-i442-x

Local gate re-run by the operator on the Mac

ruff gateway check rc=0 format rc=0
mypy rc=0 Success: no issues found in 214 source files
pytest(gateway changed tests) rc=0 65 passed, 2 warnings in 57.23s

Commits:

bf44baec test: rotation test key ids on PostgreSQL and test helper cleanup (issue #442)

Cross engine review by a different engine is posted as a PR comment.

Generated by codex for grok-bot through grok-job (job amw-b002-i442-x).

…sue #442)

Changes authored by codex in a headless grok-job run; committed by the operator.

Generated-by: codex (bot=grok-bot, job=amw-b002-i442-x)
Signed-off-by: PetrefiedThunder <131207452+PetrefiedThunder@users.noreply.github.com>
@vercel

vercel Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-middleware-web Ready Ready Preview Dec 5, 2026 6:17am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PetrefiedThunder

Copy link
Copy Markdown
Collaborator Author

Cross engine review: muse CLI (xeng fleet), read only, of codex's PR.

  1. Correct, PostgreSQL-safe rotation: test_refund_reconciliation_contention_surface.py:178 captures the original key id once, and test_refund_reconciliation_contention_surface.py:191 derives each rotated id from that fixed base truncated to the schema limit, replacing the old unbounded {key_id}-rotated-N growth (which exceeded VARCHAR(64) after a few rotations at a 40-attempt budget). Uniqueness is preserved by the -r{resolved} suffix.
  2. Correct regression guard: test_refund_reconciliation_contention_surface.py:651 asserts the exact row count and every persisted key_id length against SigningKeyModel.__table__.c.key_id.type.length, so the PostgreSQL truncation failure is caught on SQLite where VARCHAR length is not enforced. Sharing one wrapper instance via test_refund_reconciliation_contention_surface.py:212 is required for the captured base to survive across resolutions and is sound.
  3. Correct leak fix: the helper is now an @asynccontextmanager at test_mcp_upstream_governed.py:3374 with unregister_local in a finally at test_mcp_upstream_governed.py:3483, so it covers setup failures, caller-body failures, and cancellation after yield; all three callers were migrated to async with (test_mcp_upstream_governed.py:3535, 3586, 3632) with no remaining await call sites.
  4. Non-blocking coverage note: the new regression test at test_mcp_upstream_governed.py:3488 exercises only two injection points (create_tool_permit, _wallet_state) across RuntimeError/AssertionError/CancelledError, and registration at test_mcp_upstream_governed.py:3396 sits just before the try; other setup steps and caller-body failures rely on the same finally by construction rather than by test. This does not leave a demonstrated leak.
  5. Scope and hygiene confirmed: the diff touches only the two named test files with no product code, no secrets, and no synthetic product records; fault strings are test fault injection, and key ids are produced through the real rotate_active_key_metadata. PostgreSQL execution remains unverified, as reported, but the change removes the SQLite-only assumption as the acceptance criteria require.
    VERDICT: PASS

@PetrefiedThunder

Copy link
Copy Markdown
Collaborator Author

Cross engine review (round 1): Grok Build reviewer (grok-4.7), read only, of codex authored work, head bf44bae.

VERDICT: CHANGES REQUESTED

  1. gateway/app/routers/billing.py:686 (parent 3ccfb093, not commit bf44baec). This branch is claude/signing-key-retired-refuses plus one test commit: 58 commits ahead of origin/main and 0 behind. The merge-base diff adds product behavior, including assert_ready_to_sign() before a charge, plus refund, health, and signing-key changes under gateway/app/. That misses "no product code changes" and carries files from the other signing-key and refund work. Commit bf44baec itself only edits gateway/tests/test_mcp_upstream_governed.py and gateway/tests/test_refund_reconciliation_contention_surface.py. That test delta is sound: rotation ids are built from one base and cut to signing_keys.key_id (varchar 64), and _upstream_refund_failure_with_key_lost unregisters its tool in finally, including when setup raises. Fix: point the pull request at the branch that contains 3ccfb093, not at main. After that parent is on main, rebase bf44baec so the main diff is only those two test files. Do not merge this branch into main as it stands.

This branch was successfully deployed

1 active deployment
Preview — bf44baec Deployed Dec 5, 2026 by vercel[bot]
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