Skip to content

fix: keep command tests independent of ambient Gateway tokens - #118577

Merged
steipete merged 2 commits into
mainfrom
codex/qa-91-gateway-auth-token-state
Aug 3, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/qa-91-gateway-auth-token-state

Conversation

@steipete

@steipete steipete commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #118574

What Problem This Solves

Fixes an issue where command-suite validation would fail on credential-hydrated runners when OPENCLAW_GATEWAY_TOKEN was present in the ambient environment. Correct production auth resolution changed six unrelated doctor staging assertions and made a missing-token CLI test resolve instead of reject.

Why This Change Was Made

The test boundary now owns the state it depends on. The missing-token CLI case injects an empty environment explicitly, while the doctor Gateway-service suite clears and restores the Gateway token around each test; cases that intentionally exercise the token still set it through the tracked environment helper. Runtime token precedence and service-repair behavior are unchanged.

User Impact

There is no runtime behavior change. Maintainers and CI receive deterministic command-suite results regardless of Gateway credentials available on the runner.

This PR is AI-assisted with Codex. I reviewed the implementation and understand the changes.

Evidence

The Testbox wrapper returned exit 0 for both successful remote commands. Their backing Actions run may show cancellation after external lease cleanup because Blacksmith owns the delegated session lifecycle.

@steipete
steipete marked this pull request as ready for review August 3, 2026 08:02
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS maintainer Maintainer-authored PR labels Aug 3, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 4:36 AM ET / 08:36 UTC.

ClawSweeper review

What this changes

The branch makes Gateway-token command tests explicitly control their environment so credentials inherited from a runner cannot alter their expected outcomes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for maintainer handling: current main still has the ambient-environment dependency, while the branch makes the two affected test boundaries explicit without changing production Gateway authentication or service-repair behavior. The linked issue remains open until this candidate fix lands.

Priority: P2
Reviewed head: f3b5718ae80534c0be874113ba8fe705e82abb41
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow, source-aligned test repair with strong terminal proof and no identified correctness or security defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.
Evidence reviewed 6 items Current auth command reads ambient environment by default: The production command deliberately uses options.env ?? process.env for both configured and resolved Gateway-auth evaluation. The missing-token test therefore needs to pass an empty environment instead of inheriting a runner token.
Current Doctor repair path reads process environment: Gateway-service repair passes process.env to the token resolver before auditing the service, so an ambient token changes the expected repair inputs unless the suite clears it.
Candidate patch owns test state at both affected boundaries: The first commit injects an empty environment into the missing-token CLI case; the second clears and restores OPENCLAW_GATEWAY_TOKEN around the Doctor suite while preserving explicit-token cases that use the environment helper.
Findings None None.
Security None None.

How this fits together

Gateway authentication resolves its token from configuration plus an environment object, while Doctor's Gateway-service repair reads the process environment to determine the expected service token. These command tests simulate those paths; their setup must isolate runner state so test results reflect only the case being modeled.

flowchart LR
  A[Runner environment] --> B[Command test setup]
  B --> C[Gateway auth command]
  B --> D[Doctor service repair]
  C --> E[Token resolution]
  D --> E
  E --> F[Expected test assertions]
Loading

Decision needed

Question Recommendation
Should this maintainer-labelled, test-only regression fix be accepted once the required current-head check status is resolved? Accept the focused isolation fix: Merge after required checks resolve, retaining the current production behavior and closing the linked regression through the normal PR relationship.

Why: The patch appears to be the narrow owner-boundary repair, but the protected maintainer label requires an explicit human merge decision and the current check summary is not fully green.

Before merge

  • Resolve merge risk (P1) - GitHub’s current check summary includes failed or cancelled gate runs despite the PR’s supplied Testbox proof; required current-head status must be resolved through normal merge gating, but the available context does not expose logs that attribute those runs to this patch.
Agent review details

Security

None.

PR surface

Tests +7. Total +7 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 8 1 +7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 8 1 +7

Review metrics

Metric Value Why it matters
Production versus test LOC production +0, tests +8/-1 The patch changes only test ownership of environment state, matching the stated no-runtime-behavior scope.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-gateway-services.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118574
Summary: This PR is the narrow candidate repair for the linked command-test regression; it should remain open until the candidate merges.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the runtime token contract unchanged, merge the focused test-boundary isolation once required current-head checks are resolved, then let the linked regression close after the merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the runtime token contract unchanged, merge the focused test-boundary isolation once required current-head checks are resolved, then let the linked regression close after the merge.

Do we have a high-confidence way to reproduce the issue?

Yes. Current source proves both command paths consume the ambient environment, and the PR provides a deterministic forced-token command and before/after terminal results; this read-only review did not rerun the suite.

Is this the best way to solve the issue?

Yes. The patch fixes the owner boundary by making test inputs explicit while retaining the intentional production environment-resolution contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0cad02313a9c.

Labels

Label changes:

  • add P2: Ambient credentials can make command validation report false failures on credential-hydrated CI or maintainer runners, but production user behavior is unchanged.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.

Label justifications:

  • P2: Ambient credentials can make command validation report false failures on credential-hydrated CI or maintainer runners, but production user behavior is unchanged.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix terminal evidence for the exact forced-token scenario, including a repeated focused run and broader command-suite validation.

Evidence

What I checked:

  • Current auth command reads ambient environment by default: The production command deliberately uses options.env ?? process.env for both configured and resolved Gateway-auth evaluation. The missing-token test therefore needs to pass an empty environment instead of inheriting a runner token. (src/commands/gateway-auth-token.ts:37, 0cad02313a9c)
  • Current Doctor repair path reads process environment: Gateway-service repair passes process.env to the token resolver before auditing the service, so an ambient token changes the expected repair inputs unless the suite clears it. (src/commands/doctor-gateway-services.ts:595, 0cad02313a9c)
  • Candidate patch owns test state at both affected boundaries: The first commit injects an empty environment into the missing-token CLI case; the second clears and restores OPENCLAW_GATEWAY_TOKEN around the Doctor suite while preserving explicit-token cases that use the environment helper. (src/commands/doctor-gateway-services.test.ts:434, f3b5718ae805)
  • Feature-history provenance: Blame attributes the current command implementations and the affected test lifecycle to the same recent commit, including the ambient-environment reads and suite setup. This supports fixing the test boundary rather than altering runtime token precedence. (src/commands/doctor-gateway-services.test.ts:434, d6f964513f14)
  • Current main has not absorbed the candidate test changes: The PR head is based on e812630f80a35da6bdd7a3612152827d29cd2b1e and is not an ancestor of current main; both touched test paths differ between current main and the candidate head. (src/commands/gateway-auth-token.test.ts:97, f3b5718ae805)
  • After-fix behavior proof supplied in the PR: The PR body reports the forced-token focused repro passing 80/80 after the change, 20 consecutive focused runs totaling 1,600 assertions, and broader commands validation passing under the forced token. This is terminal-based after-fix proof for a test-only change. (f3b5718ae805)

Likely related people:

  • joshavant: Current runtime token-resolution lines and the affected Doctor test lifecycle all blame to the same recent feature commit. (role: recent command-auth and Doctor-service test contributor; confidence: high; commits: d6f964513f14; files: src/commands/gateway-auth-token.ts, src/commands/doctor-gateway-services.ts, src/commands/doctor-gateway-services.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready at f3b5718ae80534c0be874113ba8fe705e82abb41.

  • Root cause: two command-test boundaries inherited OPENCLAW_GATEWAY_TOKEN from credential-hydrated runners even when their scenario required no token. Production token precedence is correct and unchanged.
  • Canonical fix: the auth-token test injects an empty environment; the doctor Gateway-service suite clears/restores the token around each test while preserving explicit-token cases.
  • Scope: two test files, +8/-1, production LOC delta 0; no config, protocol, docs, dependency, or runtime surface changed.
  • Focused proof: forced-token red 6/80, then green 80/80; 20/20 stress runs, 1,600/1,600 assertions.
  • Broad proof: Testbox changed gate tbx_01kz395mx0a1px4c5zrg2q5b3c; Testbox commands run tbx_01kz39hznhe52w80fxetk7cs0c with commands-light 463/463 and full commands 3,717 passed + 3 intentional skips.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/30796088862 attempt 2 passed all selected jobs.
  • Review: fresh autoreview clean; ClawSweeper 5/6 with no findings and best-fix verdict accepted. Its CI rank-up move is resolved by the successful rerun above.
  • Live-proof gap: none applicable; this is test-only and has no external runtime boundary.

@steipete
steipete merged commit 63651a1 into main Aug 3, 2026
154 of 171 checks passed
@steipete
steipete deleted the codex/qa-91-gateway-auth-token-state branch August 3, 2026 08:48
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
…ion-routing

* origin/main:
  refactor(agents): remove stale runner state plumbing (#118495)
  test(gateway): skip servers for handler fixtures (#118581)
  test(tui): reuse real gateway PTY fixture (#118567)
  fix: keep command tests independent of ambient Gateway tokens (#118577)
  fix: show effective channel model in Telegram status (#118548)
  test(system-agent): reuse approval CLI fixture (#118572)
  test(macos): deduplicate Claude session catalog fixtures (#118571)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
…aw#118577)

* test(commands): isolate missing gateway token environment

* test(commands): isolate doctor gateway token environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Commands tests depend on ambient Gateway token state

1 participant