Repository navigation
Conversation
9ae5669 to
201c887
Compare
|
Codex review: found issues before merge. Reviewed August 14, 2026, 12:41 PM ET / 16:41 UTC. ClawSweeper reviewWhat this changesThe PR retains the runtime-effective dotenv assignment needed by each newly written environment SecretRef, removes same-file shadowing duplicates, and documents dotenv precedence. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThe core repair is still necessary and the refreshed branch fixes the current-main self-delete path, but it needs two documentation/context corrections and an explicit maintainer security-boundary decision before merge. Priority: P1 Review scores
Verification
How this fits togetherSecrets apply converts configured credentials to SecretRefs and scrubs plaintext storage. Gateway startup then loads dotenv files and resolves environment-backed references for provider authentication. flowchart LR
A[Secrets plan] --> B[Secrets apply]
B --> C[Dotenv scrub]
C --> D[Gateway startup]
D --> E[Dotenv loading]
E --> F[SecretRef resolution]
F --> G[Provider authentication]
Decision needed
Why: This is the necessary behavior for a restarted gateway to resolve an env SecretRef, but it intentionally preserves agent-readable credential material and changes the security meaning of the default scrub. Before merge
Findings
Agent review detailsSecurityNeeds attention: The branch correctly surfaces that env SecretRefs retain plaintext, but accepting that default security boundary remains a maintainer decision. PR surfaceSource +38, Tests +180, Docs +19. Total +237 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the precedence-aware repair in secrets apply, correct the cleanup promise, add the lifecycle invariant at the consuming delete, and merge only if the maintainer accepts one durable plaintext source for env SecretRefs. Do we have a high-confidence way to reproduce the issue? Yes: current main's value-based scrub and the branch's focused parsed-dotenv regression cases establish the failure and the repaired precedence path, although this review did not execute untrusted branch code. Is this the best way to solve the issue? Mostly yes: retention belongs in the sole dotenv scrub owner and matches gateway loading precedence, but the cleanup documentation and lifecycle explanation must match the narrower implementation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ffd42dd8a390. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
201c887 to
820d811
Compare
|
Rebased and addressed the open verdict items. New head
Proof regenerated and pinned to the new head. Same two-child-process run on a real temporary state directory: real Acceptance criteria re-run at this head: One item is left for maintainer judgement rather than changed. The @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
820d811 to
77dee9b
Compare
|
Rebased onto current
The state-directory restriction is the runtime contract, not a guess. Item by item:
Reviewed head was The refreshed proof in the body runs the real plan builder, real Acceptance criteria: |
77dee9b to
c6d1f39
Compare
|
Rebased and reworked the retention rule. New head The P1 was correct and the premise behind the previous head was wrong. I had claimed in the last round that "the config-adjacent Retention now follows runtime precedence instead of a hard-coded path. Item by item:
One correctness point worth calling out, since it is the security-boundary half. The fix retains exactly one assignment per ref, not every matching copy. When both files carry the same value the higher-precedence one survives and the redundant copy is deleted, so this does not widen the plaintext left on disk. Scenario B in the refreshed proof shows that run directly. Proof regenerated and pinned to the new head. Real Acceptance criteria at this head:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Retention selects each dotenv file's runtime-effective assignment for a planned env SecretRef and drops the other assignments of that name in that file, so a same-file duplicate cannot leave a fresh process authenticating with a credential apply never validated.
c6d1f39 to
2bd3590
Compare
|
Rebased onto [P1] Retain the runtime-effective dotenv assignment - fixed. Security: same-file precedence can select a stale credential - fixed by the same change, and reproduced first. Scenario C in the refreshed proof seeds one Fresh-process regression - added, table-driven over both orderings: [P2] Scope external-config dotenv guidance to gateway startup - fixed. The docs no longer claim the retained source is read by every fresh CLI and gateway process. [P3] Explain the retained-key consumption at the lifecycle boundary - answered, not as a comment. The map is renamed Merge risk: production LOC - the production delta is +48/-10, net +38, unchanged from the reviewed head even though the retention predicate is now precedence-correct. The previous Merge risk: retaining one plaintext dotenv source by default - still a deliberate tradeoff and still yours to accept or reject. It is recorded in the plan contract doc and in Stored data model - Stale base / stale proof - both cleared by the rebase and the regenerated proof above. Acceptance criteria run locally: |
What Problem This Solves
openclaw secrets configure --apply(andsecrets apply --from <plan>) rewritesmodels.providers.*.apiKeyto anenvSecretRef such asenv:default:OPENAI_API_KEY, and in the same operation deletes theOPENAI_API_KEY=assignment that the new ref resolves from. On the next start the ref the migration had just written is unresolvable:openclaw secrets auditreportsunresolved=1and the provider has no credential at all. The defect is still onmainat9386ac096632:scrubEnvFilesbuilds its key set fromlistKnownSecretEnvVarNames()with no awareness of the refs the same plan is writing, andscrubEnvRawdeletes any line whose key is in that set and whose value is one of the plaintext values the plan migrated out of config. For a plaintext-to-envmigration both conditions hold by construction.Non-goal, stated up front: this does not touch the cross-provider same-value over-scrub in #97660. Retention here is scoped to the ids the current plan's own targets read.
Why This Change Was Made
Three narrower repairs were tried and were all wrong.
Exempting the planned variable name retained a same-named value even when apply had validated a different one, so a restarted process could silently authenticate as a stale credential. Binding retention to the state-directory file fixed that but assumed the state
.envis the only dotenv source a fresh process reads, which is false: whenOPENCLAW_CONFIG_PATHpoints outside the state directory, gateway startup also loads the config directory's.env.The third, at the previously reviewed head
c6d1f394bbcc, walked the files in load order but retained the first raw line whose value matched. ClawSweeper's P1 and the medium security finding were right:readDotEnvFilereduces a file throughdotenv.parsebefore any cross-file precedence is applied, and within one file the last assignment of a name wins. A retained first line followed by a stale duplicate under the same name left the stale value effective, so a fresh gateway authenticated with a credential apply never validated. Scenario C in the proof below shows that happening onc6d1f394bbccwith the real runtime.Retention is now derived from each file's runtime-effective assignment instead of its first matching line:
durableLineByKeykeeps the last index whose parsed value equals the value apply validated the ref against, which is the assignmentdotenv.parsewould surface for that file. Every other assignment of a retained name in that file is removed, so the durable source is also the effective one and no shadowed or shadowing duplicate can become the active credential. Names with no matching assignment fall through to the unchanged scrub.Across files,
envRefValuesAwaitingSourcestarts as the plan's ownsource: "env"targets mapped toenv[ref.id], which is exactly the valuevalidateProjectedSecretsStateresolves for that ref (resolveEnvRefsinsrc/secrets/resolve.tsreturnsparams.env[ref.id]unchanged). A name is dropped from that map once a file has supplied it, so the first file that can back a ref is the only one that retains it and every lower-precedence copy is still scrubbed.The ordering is not a coincidence maintained by hand.
listSecretsDotEnvPathsreturns[stateDir/.env, dirname(configPath)/.env], andresolveGatewayRunDotEnvPathsinsrc/cli/gateway-cli/pre-bootstrap.tshandsloadGlobalRuntimeDotEnvFilesexactly[resolveStateDir/.env, resolveConfigDir/.env].loadParsedDotEnvFilesinsrc/infra/dotenv-global.tsis first-wins across that list and never overrides a value already inprocess.env. The scrubber and the loader consume the same sequence.scrubEnvFilesis the only place that decides which dotenv assignments a plan removes, so the self-delete, the stale-retention hazard, the same-file precedence hazard, and the external-config case are all decided in one function. Nothing downstream compensates.Sibling surfaces:
scrubAuthProfilesForProviderTargetsandscrubLegacyAuthJsonclear stores that env SecretRefs never read from, so neither can delete a ref's source; they are unchanged.fileandexecrefs never read a dotenv assignment, so they are skipped and their scrub behavior is unchanged.~/.config/openclaw/gateway.envis loaded by the runtime but is not inlistSecretsDotEnvPaths, sosecrets applynever scrubbed it and still does not. Working-directory.envfiles are likewise outsidelistSecretsDotEnvPaths.User Impact
An operator who migrates a provider credential to an
envSecretRef keeps a working provider after restart instead of an unresolvable ref, and the credential a restarted gateway resolves is the one apply validated rather than a stale duplicate that happened to sit later in the same file. Withoptions.scrubEnvoff nothing changes, and every dotenv value not backing one of this plan's own env refs is scrubbed exactly as before; the pre-existing scrub assertions pass unmodified.Production delta is +48/-10 in one file, net +38, unchanged from the previously reviewed head even though the retention predicate is now precedence-correct. Docs +20/-1, tests +182/-2.
Evidence
node scripts/run-vitest.mjs src/secrets/apply.test.ts- 43 passed.removes a same-file duplicate declared before/after the retained env SecretRef sourcefails on the rebased previous head withexpected [ Array(1) ] to include <stateEnvPath>(the.envwas never rewritten, so the shadowing duplicate survived) and passes here. That is the P1 regression ClawSweeper asked for.node scripts/run-oxlint.mjs src/secrets/apply.ts src/secrets/apply.test.ts- clean.oxfmt- clean.tsgo -p tsconfig.core.json- no diagnostic insrc/secrets; the only output is pre-existingTS4058/TS2883declaration-naming noise insrc/auto-reply/**,src/infra/embedded-state-lock.ts, andsrc/media-understanding/**caused by this worktree resolving@types/nodethrough a linkednode_modules.node scripts/check-docs-mdx.mjs- passed, 772 files.node scripts/docs-link-audit.mjs- 6495 internal links, 0 broken.git diff --check- clean.Rebased onto
main9386ac096632with no conflicts.Real behavior proof
Behavior addressed:
openclaw secrets configure --applydeleted the.envassignment that theenvSecretRef it had just written resolves from, leaving the provider with no credential in every fresh gateway process; withOPENCLAW_CONFIG_PATHoutside the state directory the deleted file was the config-adjacent.env. At the previously reviewed head the retained line was the first raw match rather than the file's effective assignment, so a later duplicate under the same name stayed effective and a fresh gateway resolved a credential apply never validated.Real environment tested: real
buildConfigureCandidatesForScopeplusbuildSecretsConfigurePlanplusrunSecretsApplyin one process, then realloadGlobalRuntimeDotEnvFilesand realresolveSecretRefValuein a second process started after the operator shell export is gone, both against one temporary state directory, on pristinemain9386ac096632, on the previously reviewed headc6d1f394bbccrebased onto that same main, and on this branch head2bd3590467904b89e4f8ce79873402257dd4c395. Nothing is stubbed: real dotenv startup hydration using the same path selectionresolveGatewayRunDotEnvPathsmakes, real plan builder, real apply writer, real dotenv scrubber, real resolver, real files on disk.Exact steps or command run after this patch:
node --import tsx apply-run.mts <root> <scenario>to seed the config and.envfiles for the scenario and run the apply, thenenv -u OPENAI_API_KEY node --import tsx fresh-gateway-run.mts <root> <scenario>to hydrate a second process from the gateway dotenv set and resolve the provider ref.Evidence after fix:
Observed result after fix: in scenario A the provider moves from having no credential after restart to resolving
sk-openai-live-9c2ffrom the config-adjacent file a fresh gateway actually loads. In scenario B only the higher-precedence assignment survives and the redundant lower-precedence copy is removed, so one readable source per ref is kept rather than every matching one. In scenario C both pristine main and the previously reviewed head hand the restarted processsk-openai-rotated-out-4a11, a credential apply never validated; this patch removes the shadowing duplicate and the restarted process resolvessk-openai-live-9c2f.What was not tested: no live provider request is made, only the credential a restarted process resolves; no managed gateway service restart was driven, the second process stands in for it using the same dotenv path selection gateway startup makes; the full build was not run;
~/.config/openclaw/gateway.envand working-directory.envfiles are loaded by the runtime but are not inlistSecretsDotEnvPaths, so they are neither scrubbed nor retained here.Documentation
docs/gateway/secrets.mdgains aRetained dotenv sourcessection. It names the two filessecrets applyscrubs in the order the gateway loads them, states that onlyopenclaw gateway runloads the active config directory's.envwhile normal CLI commands load the working-directory and state-directory files instead, and therefore that a ref whose only retained source is the config-directory file resolves in the gateway but not in a fresh CLI such as the post-applyopenclaw secrets audit. It states the two precedence rules that make retention correct: first file wins across files, last assignment wins within a file, which is why the other assignments of a retained name in that file are removed. The agent-access boundary section still says plainly that anenvSecretRef does not satisfy that boundary: the retained line stays agent-readable, the re-audit keeps reportingPLAINTEXT_FOUND, and completing the boundary requiresfileorexecrefs.docs/gateway/secrets-plan-contract.mdrecords thescrubEnvretention rule in the same terms.Open maintainer decisions
scrubEnvdefault-behavior change on an auth path. After this lands, an upgrade that migrates a dotenv value to anenvref keeps that one line instead of deleting it, and removes the other assignments of that name in the same file. That is the intended repair and it is recorded in the plan contract doc, but it changes a default-on scrub on a credential path and is worth an explicit accept. ClawSweeper also flags aStored data modelchange onsrc/secrets/apply.test.ts; that file is fixture JSON inside a suite, and no on-disk format, schema version, or persisted shape changes in this PR.P3 asked for the invariant as a comment at the call site; it is carried by naming and docs instead. The map is now named
envRefValuesAwaitingSource, soenvRefValuesAwaitingSource.delete(retainedKey)reads as consuming a pending ref rather than as ordinary map cleanup, and the lifecycle invariant itself is written down indocs/gateway/secrets-plan-contract.mdand the newRetained dotenv sourcessection. RootAGENTS.mddoes ask for an inline comment on cross-path lifecycle ordering, so if a maintainer wants it at the code site rather than in the name, say so and it goes in.Production delta is +38, not net-neutral. The growth is the retention predicate, its inputs, and the first-wins bookkeeping. Absorbing it into an existing owner would mean giving
scrubEnvRawknowledge of the file list, which merges two responsibilities rather than removing one, so the delta is proposed as justified rather than avoidable.