fix: block unexpected Codex refresh scopes#1412
Draft
simple-agent-manager[bot] wants to merge 4 commits into
Draft
fix: block unexpected Codex refresh scopes#1412simple-agent-manager[bot] wants to merge 4 commits into
simple-agent-manager[bot] wants to merge 4 commits into
Conversation
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
CODEX_SCOPE_VALIDATION_MODEenv surface so warn-and-persist cannot be restored accidentally.CODEX_EXPECTED_SCOPES=""still succeed.Validation
pnpm lintpnpm typecheckpnpm testpnpm buildpnpm --filter @simple-agent-manager/api test -- tests/unit/durable-objects/codex-refresh-lock.test.tspnpm --filter @simple-agent-manager/api typecheckpnpm --filter @simple-agent-manager/api lintNote: first full
pnpm testattempt hit an unrelated@simple-agent-manager/infradns.test.tsbeforeAll timeout. Direct retry ofpnpm --filter @simple-agent-manager/infra testpassed, and fullpnpm testthen passed.Staging Verification (REQUIRED for all code changes — merge-blocking)
Staging Verification Evidence
Not performed by explicit task constraint. This PR is draft and labeled
needs-human-review; human reviewer owns staging verification and merge.UI Compliance Checklist (Required for UI changes)
End-to-End Verification (Required for multi-component changes)
Data Flow Trace
Codex refresh request enters
CodexRefreshLock.fetch()and calls the upstream token endpoint. After successful upstream response parsing,apps/api/src/durable-objects/codex-refresh-lock.tsvalidatesnewTokens.scopebeforerecordRotatedToken(),encrypt(), andUPDATE credentials. On validation failure it returns502 upstream_unexpected_scope, leaving the prior credential row unchanged.Untested Gaps
No staging/live-provider verification was run by explicit instruction. Local unit coverage uses mocked upstream refresh responses and asserts both response behavior and D1/encryption side effects.
Post-Mortem (Required for bug fix PRs)
What broke
Codex token refresh accepted rotated upstream tokens with unexpected scopes by default and persisted them after warning.
Root cause
The refresh lock had a validation mode fallback of
?? 'warn', causing unexpected scopes to log and proceed unless an explicit block mode was configured.Class of bug
Credential rotation validation failed open due to warn-only fallback behavior.
Why it wasn't caught
Existing tests encoded warn-and-persist as the expected default behavior.
Process fix included in this PR
Tests now assert fail-closed behavior, non-persistence on rejected rotations, default allowlist enforcement when
CODEX_EXPECTED_SCOPESis absent, and explicit opt-out only viaCODEX_EXPECTED_SCOPES="".Post-mortem file
tasks/archive/2026-06-25-codex-refresh-scope-block.mdSpecialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to humanCODEX_EXPECTED_SCOPESoverride.CODEX_SCOPE_VALIDATION_MODEfrom runtime Env interface; no runtime/docs references remain outside the regression test.Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: no external API contract change; work was based on local task context, rule 28, and existing code/tests.
Codebase Impact Analysis
Affected components: Codex refresh Durable Object, API Env interface, and unit tests for
codex-refresh-lock.Documentation & Specs
No user-facing docs changed. The stale env interface entry was removed because
CODEX_SCOPE_VALIDATION_MODEis no longer a supported runtime control. Task archived attasks/archive/2026-06-25-codex-refresh-scope-block.md.Constitution & Risk Check
Checked fail-closed credential rotation behavior, no hardcoded-value regression, and env consistency. Main behavior tradeoff: unexpected provider scope changes now block refresh unless explicitly opted out with
CODEX_EXPECTED_SCOPES="", matching Rule 28.