Repository navigation
fix(sessions): scope legacy-main owner notice to real legacy rows - #126551
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 1:39 AM ET / 05:39 UTC. ClawSweeper reviewWhat this changesThe PR checks candidate SQLite session stores for actual retired main-agent rows before showing an unresolved-owner migration notice or blocking creation of a main agent. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep this maintainer-authored PR open. Source review finds the migration-owner fix coherent and no blocking patch defect; exact-head CI is still incomplete with one failed compact check requiring resolution before merge. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway startup and agent creation consult session migration to detect retired main-agent session keys. The migration result either preserves a warning/gate for real or uncertain legacy data, or lets a clean new fleet continue. flowchart LR
A[Gateway startup or agent creation] --> B[Session migration check]
B --> C[Resolve configured owner]
C --> D[Scan candidate session stores]
D --> E{Legacy rows or uncertainty?}
E -->|Yes| F[Keep notice or creation gate]
E -->|No| G[Continue normally]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +95. Total +161 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk options
Maintainer options:
Technical reviewBest possible solution: Retain the migration-owner scan and fail-open behavior, then merge only after exact-head checks confirm both clean-store and uncertain-store paths. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main emits the unresolved-owner result before store inspection and blocks unarmed main-agent creation; the PR also provides an isolated gateway before/after transcript. I did not execute the reproduction in this read-only checkout. Is this the best way to solve the issue? Yes: placing absence proof in the migration owner is better than special-casing gateway or agent-creation consumers, and the shared scanner keeps the armed and unarmed paths on one key predicate. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0a8226c3db52. LabelsLabel changes:
Label justifications:
EvidenceWhat 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
|
resolveArmingDecision returns owner-unresolved purely from config, before any session store is read, so the unresolved-owner notice and the agents-create gate both fired without checking whether any legacy `main` rows exist. A new explicit-ownership fleet with zero session data printed "legacy main rows have no unambiguous configured owner" on every startup, and `agents create main` dead-ended: it told operators to run `openclaw doctor --fix`, which cannot resolve anything when there is nothing to migrate. Probe the candidate stores in the unresolved-owner branch and report no-legacy-rows when every store proves clean. Unreadable stores, legacy JSON stores, and genuine read failures still fail open and keep the notice, so the precaution survives exactly where absence cannot be proven. The main-creation gate now blocks an unarmed run only when the scan did not prove the fleet clean; armed runs still require a completed ledger. Store scanning moves to legacy-main-session-key-scan.ts: the probe and the armed claim reader share one normalization-aware key predicate, so a store holding `agent:Main:...` or another key that normalizes to `main` cannot be misread as clean, and the migration module stays under the max-lines limit.
…order src/gateway/server.sessions.compaction-read-errors.test.ts captured the real loadTranscriptEvents as a side effect of its vi.mock factory, then required it in beforeEach. The factory runs on first import of the mocked module, so once a shard shares a worker (--isolate=false) the field could still be unset and all five tests failed with "transcript reader mock was not initialized". Resolve the real reader with vi.importActual in beforeAll instead, so the default implementation no longer depends on whether the factory has run. Pre-existing on main: 0a8226c fails the same checks-node-compact-small-4 shard with the identical five tests. Not reproducible locally, including with the exact 25-file shard composition; CI on Linux runners is the verification.
src/gateway/server.sessions.compaction-read-errors.test.ts captures the real loadTranscriptEvents as a side effect of its vi.mock factory and requires it in beforeEach. The factory only runs when the mocked module is first imported, and nothing in this file imported it directly, so once a shard shares a worker (--isolate=false) the capture could still be unset and all five tests failed with "transcript reader mock was not initialized". Import the mocked module for its side effect so the factory always runs. Resolving the reader with vi.importActual instead was wrong: that returns a separately instantiated, unmocked copy that does not share the module-level SQLite state the harness sets up, so it read no events, compaction no-opped successfully and the three rejection tests failed on response.ok. Capturing through importOriginal keeps the harness's own module instance. Pre-existing on main: 0a8226c fails the same checks-node-compact-small-4 shard with the identical five tests.
8d08e44 to
8093878
Compare
|
Merged via squash.
|
…enclaw#126551) * fix(sessions): scope legacy-main owner notice to real legacy rows resolveArmingDecision returns owner-unresolved purely from config, before any session store is read, so the unresolved-owner notice and the agents-create gate both fired without checking whether any legacy `main` rows exist. A new explicit-ownership fleet with zero session data printed "legacy main rows have no unambiguous configured owner" on every startup, and `agents create main` dead-ended: it told operators to run `openclaw doctor --fix`, which cannot resolve anything when there is nothing to migrate. Probe the candidate stores in the unresolved-owner branch and report no-legacy-rows when every store proves clean. Unreadable stores, legacy JSON stores, and genuine read failures still fail open and keep the notice, so the precaution survives exactly where absence cannot be proven. The main-creation gate now blocks an unarmed run only when the scan did not prove the fleet clean; armed runs still require a completed ledger. Store scanning moves to legacy-main-session-key-scan.ts: the probe and the armed claim reader share one normalization-aware key predicate, so a store holding `agent:Main:...` or another key that normalizes to `main` cannot be misread as clean, and the migration module stays under the max-lines limit. * test(gateway): stop compaction read-error mocks depending on factory order src/gateway/server.sessions.compaction-read-errors.test.ts captured the real loadTranscriptEvents as a side effect of its vi.mock factory, then required it in beforeEach. The factory runs on first import of the mocked module, so once a shard shares a worker (--isolate=false) the field could still be unset and all five tests failed with "transcript reader mock was not initialized". Resolve the real reader with vi.importActual in beforeAll instead, so the default implementation no longer depends on whether the factory has run. Pre-existing on main: fadb67d fails the same checks-node-compact-small-4 shard with the identical five tests. Not reproducible locally, including with the exact 25-file shard composition; CI on Linux runners is the verification. * test(gateway): load the mocked transcript reader deterministically src/gateway/server.sessions.compaction-read-errors.test.ts captures the real loadTranscriptEvents as a side effect of its vi.mock factory and requires it in beforeEach. The factory only runs when the mocked module is first imported, and nothing in this file imported it directly, so once a shard shares a worker (--isolate=false) the capture could still be unset and all five tests failed with "transcript reader mock was not initialized". Import the mocked module for its side effect so the factory always runs. Resolving the reader with vi.importActual instead was wrong: that returns a separately instantiated, unmocked copy that does not share the module-level SQLite state the harness sets up, so it read no events, compaction no-opped successfully and the three rejection tests failed on response.ok. Capturing through importOriginal keeps the harness's own module instance. Pre-existing on main: fadb67d fails the same checks-node-compact-small-4 shard with the identical five tests.
What Problem This Solves
Fixes an issue where operators starting a correctly configured multi-agent fleet would see a Doctor notice claiming legacy
mainsession rows needed an owner, on a brand-new install with zero session data.Every gateway startup printed:
The wording implies data exists and asks the operator to assign ownership for nothing. Running
openclaw doctorcannot clear it, because there is nothing to migrate.The same unresolved-owner result also dead-ended agent creation.
openclaw agents create mainfailed withlegacy main sessions have no unambiguous configured owner ... Run openclaw doctor --fix, then retry, on a fleet with no legacy rows.doctor --fixcould never resolve it, so the only escape was configuringagents.defaults.sessionStore.agentIdto satisfy a check about data that did not exist.Why This Change Was Made
resolveArmingDecisiondecides ownership purely from config and returns before any session store is read, so the notice and the creation gate had never been conditional on data. Neither surface had ever checked whether a legacy row exists.The unresolved-owner branch now probes the candidate stores and reports
no-legacy-rowswhen every store proves clean. Absence must be proven: unreadable stores, legacy JSON stores, and genuine read failures still fail open and keep the notice, so the precaution survives exactly where the fleet cannot be shown clean.Store scanning moved into
legacy-main-session-key-scan.tsso the probe and the armed claim reader share one normalization-aware key predicate. This matters for correctness:normalizeAgentIdfalls back tomainfor unrepresentable ids, so keys such asagent:---:chatare genuine legacy rows. A rawLIKE 'agent:main:%'probe would have missed them and silenced a real pending migration. The extraction also keepslegacy-main-session-migration.tsunder the max-lines limit (703 -> 689) without adding a suppression.The creation gate now blocks an unarmed run only when the scan did not prove the fleet clean. Armed runs still require a completed ledger, so every previously blocked outcome still blocks.
User Impact
A correctly configured new fleet starts clean, and
agents create mainis no longer blocked by a migration that has nothing to migrate. Operators with real legacymainrows see exactly the same notice and the same gate as before.Evidence
Live gateway startup, isolated
OPENCLAW_STATE_DIR, non-default port, identical config both runs:Before (pre-fix build):
After (rebuilt from the fixed sources, same command and config):
No migration warning block. The gateway reaches listening normally.
Config used for both runs:
{ "gateway": { "mode": "local", "port": 19199 }, "agents": { "ownership": "explicit", "defaults": { "systemAgent": { "agentId": "ops" } }, "entries": { "ops": {}, "research": {}, "support": {} } } }Regression coverage. The new
state-migrationscase fails on pre-fix code for the right reason:The pre-existing unresolved-owner tests were changed to seed a real
agent:main:chatrow before asserting the notice, since they previously asserted it on an empty store. New cases cover the proven-clean store, the unreadable-store fail-open, and unarmed-but-clean agent creation.Test and check runs:
Codex autoreview on the full diff: clean, no accepted or actionable findings.
Production LOC delta is +66 (tests +95). This is a bug fix, so the growth is called out deliberately rather than left for review to find. Proving absence is a capability that did not exist anywhere in this module: the arming decision is config-only by design, and it must stay that way because the exported error path calls it from a
catchwhere store I/O would be wrong. The absorbing refactor was attempted and taken as far as it goes: the probe reusesresolvePhysicalStoresfor discovery instead of adding a second path, the armed reader and the probe now share one key predicate instead of two copies, and a double parse of every session key was removed along the way. What remains is the probe itself, the owner-optional plumbing, and the import header of the extracted module.Unrelated CI heal included
mainwas already red when this branch was cut. Base commit0a8226c3failschecks-node-compact-small-4with the same five tests and the same error as this PR's first run:That file captures the real
loadTranscriptEventsas a side effect of itsvi.mockfactory and requires it inbeforeEach. The factory only runs when the mocked module is first imported, and nothing in the file imported it directly, so once a shard shares a worker (--isolate=false) the capture could still be unset. Flaky by construction, not by timing.Fixed here rather than waited out, per the repo rule that red
maingets fixed in the landing PR: the file now imports the mocked module for its side effect, so the factory always runs.The first attempt in this branch resolved the reader with
vi.importActualinstead, and CI caught that it was wrong.importActualreturns a separately instantiated, unmocked copy that does not share the module-level SQLite state the harness sets up, so it read no events, compaction no-opped successfully, and the three rejection tests failed onresponse.okwhile the two empty-transcript tests passed. Capturing throughimportOriginalkeeps the harness's own module instance; only the import was missing.Honest limitation: this does not reproduce locally, including with the exact 25-file shard composition taken from the failing CI log (25 files, 300 tests, green before and after). CI on the Linux runners is the verification for this part.