Skip to content

fix(doctor): preserve explicit session store agent selector - #156907

Merged
obviyus merged 5 commits into
openclaw:mainfrom
Alix-007:alix/fix-doctor-explicit-agent-20260924
Sep 29, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
Alix-007:alix/fix-doctor-explicit-agent-20260924

Conversation

@Alix-007

@Alix-007 Alix-007 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Doctor silently accepts a different session-store owner when an explicit store path and an expected agent selector are supplied together.

User Impact

Doctor honors the expected owner for an explicit session store. Matching selectors keep working; an owner mismatch is rejected rather than inspecting another agent's store. No options, defaults, schemas, or permissions are added.

Maintainer decision (Ayaan, September 29): accepted the CLI compatibility change. Existing scripts that pass a store belonging to a different agent now exit with an ownership error; use the matching expected owner. This resolves the compatibility decision requested in the exact-head review.

Why This Change Was Made

Forward the existing agent and allAgents options to the existing session-store resolver instead of dropping them in Doctor's explicit-store branch. The shared resolver remains the single owner of selector conflicts and ownership checks.

Thanks to @Alix-007 for reporting and contributing this fix, including the clawtributors report. No overlap with Pash/Sarah changes was found in the two changed files.

Caller compatibility and update behavior

The documented contract is an expected database owner, not an ownership override: Doctor SQLite selectors. A mismatch must reject. Silently using another owner is the bug being corrected.

Caller Before After
Doctor CLI --session-sqlite-store plus --session-sqlite-agent (register.maintenance.ts, doctor.ts) Both flags reach Doctor, but its target resolver drops the agent's explicit-selector status. An existing other store can be inspected despite requesting main. Both reach the shared resolver; matching other succeeds, requesting main rejects.
Destructive Doctor maintenance path admission (resolveExplicitSessionSqliteMaintenancePaths in doctor.ts) Already forwards store, agent, and all-agents before acquiring maintenance authority. Unchanged. The later target resolution and publication reconciliation now agree with that admission check.
Doctor target inspection/migration and publication reconciliation (doctor-session-sqlite.ts) Both call the affected target resolver; explicit selectors can be discarded there. Both use the repaired resolver. No import, restore, or schema writer changes.
Sessions listing, tail, and cleanup (session-store-targets.ts, sessions*.ts, cleanup-service.ts) Already pass store and agent to the shared resolver. Unchanged; these do not call the affected Doctor adapter.
Installed update Doctor driver (update-command-package.ts) and candidate canary Invoke ordinary Doctor/fix or its dedicated finalizer, without session-store/agent selector pairs. Unchanged; they never enter this explicit-store branch.
Upgrade-survivor project-worktree import driver (scripts/e2e/lib/upgrade-survivor/run.sh, run_project_worktree_import) Passes its main-owned legacy store and --session-sqlite-agent main. The matching main selection is unchanged. It does not rely on ignoring a mismatched selector.

No shipped caller was found relying on a mismatched pair. Ordinary update discovery is unchanged. This patch introduces no migration: it repairs selection before the existing data operations, preserving existing ownership refusal rather than adding a new policy.

Evidence

Observed on September 29 with the published npm [email protected] binary (eb377ac), baseline b578706c394ebf6b486ce54a2817356b0bac77d8, and built candidate 6daa40edfbd49519d8e5f78f42e30f2442826eb3:

  1. Installed the published package in an isolated directory. Its CLI created agent other; agents list --json confirmed existing main and other. Published Doctor imported a synthetic existing session into the canonical other database, reporting one imported entry and no issues.
  2. Every product command used explicit --profile p156907base or --profile p156907cand, task-owned home/state/config paths and a unique port. Before the comparison commands, each exact binary printed its resolved config and database paths; the runner checked these remained inside the isolated tree and rejected live .openclaw paths. No Gateway or external service was started.
  3. Ran the actual checkout CLI through pnpm openclaw after its build, against that published operator state:
--profile p156907base doctor --session-sqlite inspect \
  --session-sqlite-store <isolated-state>/agents/other/sessions/sessions.json \
  --session-sqlite-agent main --json
baseline: exit 0, agentId=other, sqliteEntries=1, integrityCheck=ok

--profile p156907cand doctor --session-sqlite inspect \
  --session-sqlite-store <isolated-state>/agents/other/sessions/sessions.json \
  --session-sqlite-agent main --json
candidate: exit 2
Session store belongs to agent "other", not requested agent "main".
  1. The same command with --session-sqlite-agent other succeeded on both baseline and candidate: exit 0, agentId=other, one SQLite entry, integrity ok, no issues. This proves matching-selector compatibility on existing published state, not only on a freshly created candidate fixture.
  2. PRAGMA user_version stayed 18 for shared state and 23 for both inspected agent databases. Sorted sqlite_schema definitions had identical SHA-256 hashes before and after candidate Doctor: shared state 01688835cfc2401f2a79b4ed07490e03b945a323b325e2045bba3a3e456b5adb; agent schema f858712016891962a11c50c0bbd8fb314f26571f1bed278306ae998b9242599d. The published binary could still inspect the same session afterward, with integrity ok and no issues.

This is published-state-to-candidate Doctor upgrade compatibility proof. It does not claim a full package replacement, service restart, or rollback transaction. Earlier contributor receipts additionally recorded real import/restore/inspect on production-identical head e0199b25bd6f18e699874c9f89c20b23c04812c4; later commits changed only test-fixture cleanup and commit metadata.

The complete patch remains one selector-forwarding change and one focused regression (+27/-1 across two files); no additional abstraction or production change was needed.

Hosted checks

The existing September 26 run 36240560027 is red: checks-node-changed-compact-large-43 failed update-cli fresh-doctor, post-core-recovery, restart-sentinel, and Windows-recovery cases; openclaw/ci-gate is a derived failure. Twelve other jobs were cancelled, not independent test failures. No job was rerun and no empty commit was pushed. This run is retained as historical evidence, not a new green claim.

Focused candidate regression: node scripts/run-vitest.mjs src/commands/doctor-session-sqlite.explicit-agent.test.ts --maxWorkers=1 passed 1/1 through the registered unit-fast suite. Test body: 3 ms; Vitest: 44.93 s; total wall including cold worker preparation: 54.289 s. All inherited OPENCLAW_* variables were cleared for the test process. The earlier explicitly selected commands-suite invocation found no tests because this test is routed to unit-fast; it is not counted as a test pass.

Current-main integration and failure controls

Integrated main d812797ec244 into the contributor branch as 7dfbe98f29fed2047f370e033bd4652253c44169, preserving all contributor commits. The named material base risk was the five-day-old base plus Doctor/update behavior, not a desire to rerun CI. The PR delta against integrated main remains exactly the two files above.

Ran the current update/Doctor comparison locally with inherited OPENCLAW_* variables removed and --maxWorkers=2:

  • Integrated candidate: 40 files, 509 tests passed, 814.169 s wall.
  • PR-reverted control (the exact integrated main tree, without these two-file PR changes): 39 files, 508 tests passed, 634.983 s wall. The one-test difference is this PR's new selector regression.
  • Scope: update-cli.fresh-doctor.test.ts, update-cli.target-schema.test.ts, update-cli.windows-lifecycle.test.ts, update-cli.post-core-handoff.test.ts, update-command-post-core.test.ts, update-command-post-core-failure.test.ts, and all doctor-session-sqlite*.test.ts files.
  • Three historical failing filenames no longer exist on current main. The old restart-sentinel plugin-load assertion survives in target-schema; the old Windows recovery assertions survive in windows-lifecycle and use mocked Windows platform state, so they ran successfully on macOS. This is not a native Windows service proof. Current post-core owner/handoff suites cover that refactored path; removed historical cases are not represented as rerun verbatim.
  • No failures were added by the PR in this comparison. The cancelled historical run's 12 compressed shard plans were recovered, but that old merge's cancelled jobs are not claimed green from the local comparison.
  • Rebuilt and repeated the real pnpm openclaw mismatch/matching comparison on integrated head 7dfbe98f29fed2047f370e033bd4652253c44169, using the same published operator state: mismatch rejected with exit 2; matching other returned one entry, integrity ok, and no issues. Shared/agent versions and all recorded schema hashes remained identical.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: S labels Sep 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 3:02 AM ET / 07:02 UTC (Revision 12).

ClawSweeper review

What this changes

Doctor now forwards explicit session-store agent selectors to the shared resolver and adds a regression test for selecting a non-default agent.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful fix: current main still drops Doctor’s explicit agent selector, while the PR restores the documented owner check. The repository user who accepted the resulting CLI compatibility change has verified maintain permission. No actionable patch defect remains.

Priority: P2
Reviewed head: 7dfbe98f29fed2047f370e033bd4652253c44169

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow shared-owner repair has direct CLI proof, published-state observations, and a focused regression test, with its compatibility tradeoff accepted.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body records real Doctor CLI inspection on published-release operator state through the integrated candidate: a mismatched owner is rejected before inspection, while a matching selector returns the existing session with integrity OK. The patch changes target selection, not a stored-data contract, so data-model compatibility is not applicable.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records real Doctor CLI inspection on published-release operator state through the integrated candidate: a mismatched owner is rejected before inspection, while a matching selector returns the existing session with integrity OK. The patch changes target selection, not a stored-data contract, so data-model compatibility is not applicable.
Evidence reviewed 8 items Introduced repair: The pinned PR delta forwards the existing agent and all-agents selectors in Doctor’s explicit-store branch.
Current-main gap: Fetched main still passes only the store path in this branch, so it does not implement the PR’s fix.
Existing ownership contract: The shared resolver rejects a requested agent that differs from the explicit store’s owner before returning a target.
Findings None None.
Security None None.

How this fits together

Doctor receives session-store paths and agent selectors from the CLI before inspecting or maintaining session SQLite data. A shared resolver identifies the store owner and returns a target or an ownership error.

flowchart LR
  A[Doctor CLI options] --> B[Doctor target selection]
  B --> C[Shared store resolver]
  C --> D{Owner matches?}
  D -->|Yes| E[Selected session database]
  D -->|No| F[Ownership error]
  E --> G[Inspect or maintain sessions]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +4, Tests +22. Total +26 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 22 0 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 27 1 +26

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-sqlite-targets.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep Doctor’s inspection and maintenance paths on the shared store-owner check, with a clear error for mismatched selectors.

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

Yes. Current-main source drops the selector, and the PR records before-and-after Doctor CLI results for a mismatched store owner; I did not execute the CLI in this read-only review.

Is this the best way to solve the issue?

Yes. Forwarding the existing selectors lets the shared resolver enforce its documented owner check without a second policy or stored-data change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ab26b89a6aa1.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR fixes a bounded Doctor selector bug affecting explicit session-store commands.
  • merge-risk: 🚨 compatibility: Existing scripts with mismatched store and agent selectors will receive an ownership error; the repository’s maintain-permission decision maker explicitly accepted that tradeoff.
  • 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 records real Doctor CLI inspection on published-release operator state through the integrated candidate: a mismatched owner is rejected before inspection, while a matching selector returns the existing session with integrity OK. The patch changes target selection, not a stored-data contract, so data-model compatibility is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records real Doctor CLI inspection on published-release operator state through the integrated candidate: a mismatched owner is rejected before inspection, while a matching selector returns the existing session with integrity OK. The patch changes target selection, not a stored-data contract, so data-model compatibility is not applicable.

Evidence

What I checked:

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-24T09:14:11.422Z sha e0199b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-24T14:10:59.033Z sha e0199b2 :: blocked before merge. :: [P3] Use the shared temporary-directory tracker in the new test
  • reviewed 2026-09-24T14:37:26.580Z sha c3385bac092516e2d2c14dd70daa111e815af0b2 :: blocked before merge. :: none
  • reviewed 2026-09-26T12:07:50.626Z sha 6daa40e :: blocked before merge. :: none
  • reviewed 2026-09-26T12:14:55.613Z sha 6daa40e :: blocked before merge. :: none
  • reviewed 2026-09-26T12:29:34.920Z sha 6daa40e :: blocked before merge. :: none
  • reviewed 2026-09-29T06:19:36.122Z sha 6daa40e :: blocked before merge. :: none
  • reviewed 2026-09-29T06:51:12.900Z sha 7dfbe98 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed agents Agent runtime and tooling size: S labels Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added exact-head real CLI proof to the PR body for #156907. It covers explicit non-default agent import, restore, canonical inspect, and the owner-mismatch control, with exit codes and redacted outputs; the focused regression is 1/1 passed. No credentials or private paths are included.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The prior exact-review worker failed before publishing an artifact; the exact-head CLI evidence and focused-test timing remain in the PR body. Please retry the review queue.

@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Remaining Doctor upgrade gate: exact-head isolated execution started

The accepted explicit-agent import/restore/ownership evidence and its stated revision scope remain unchanged. To address the separate published-driver × candidate upgrade gate, a fork-only hosted run is now executing the existing repository validation against the exact reviewed head:

Observed status at this update: exact-head checkout and frozen dependency installation passed; candidate build is in progress. The package and published-upgrade stages have not completed. No upgrade PASS or merge-readiness change is claimed, and this execution record does not replace the previously accepted functional proof.

@Alix-007
Alix-007 force-pushed the alix/fix-doctor-explicit-agent-20260924 branch from c3385ba to 6daa40e Compare September 26, 2026 12:00
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 26, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 26, 2026
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 29, 2026
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Maintainer decision from Ayaan (2026-09-29): accepted the CLI compatibility change requested in #156907 (comment). Mismatched explicit store/agent pairs now exit with an ownership error, as the documented expected-owner contract requires; matching pairs remain unchanged. The PR body now records this acceptance. No code or head change.

@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Maintainer landing on exact head 7dfbe98f29fed2047f370e033bd4652253c44169.

Review. The ClawSweeper review (revision 12) has no findings and accepts the proof. It is blocked only by:

  • the compatibility decision, which the maintainer accepted: mismatched store/agent selectors now exit with an ownership error (acceptance);
  • the path-based data-model checkbox, which the review marks not applicable. This is a standing maintainer override.

Inherited failure (AGENTS.md: pre-existing reds do not block landing). Run 36532549339 finished with no cancelled jobs, and its only failing job is outside this diff (two Doctor session-SQLite files). checks-node-changed-compact-small-4 fails in server.node-pairing-authz.test.ts, "projects an operator rename immediately and after the node reconnects", with waitFor timing out at 584:18. The same case times out at the same line on PR #149850: job 109282656064.

Proof. The real Doctor CLI run on state from the published release: a mismatched selector exits 2 before inspecting anything, while a matching selector inspects the existing entry with integrity OK. Schema versions and hashes are unchanged. 509 scoped tests pass with this PR and 508 on main, with no new failures.

@obviyus
obviyus merged commit 8a04eb6 into openclaw:main Sep 29, 2026
246 of 249 checks passed
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Alix-007 for the report and fix! Landed as 8a04eb6. The real Doctor CLI comparison on published-release operator state confirmed that mismatched explicit store/agent pairs now exit with an ownership error (exit 2), while a matching selector still returns the existing session with integrity OK. Recorded schema versions and hashes remained unchanged.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…#156907)

* fix(auth): reject empty environment credentials

* fix(doctor): preserve explicit session store agent selector

* test(doctor): use lifecycle-owned temp directory for agent selector

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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.

2 participants