Skip to content

fix(sessions): preserve assigned owners through Doctor and startup repairs - #127706

Merged
steipete merged 1 commit into
mainfrom
codex/doctor-session-owner-repair-qa
Aug 22, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/doctor-session-owner-repair-qa

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators who assign responsibility for a session lose that assignment, see the wrong person listed as owner, or encounter a stuck migration after running openclaw doctor --fix, renaming the main agent, or moving a session between agent stores.

Why This Change Was Made

Assigned responsibility lives in five dedicated SQLite columns, while legacy-main migration, quarantine, cross-store import, malformed-row recovery, and canonical Doctor repair previously copied only the session payload. Reuse one transactional ownership writer at each authoritative SQLite migration boundary, preserve the selected winner's exact actor/assigner/timestamp, clear stale destination assignments, and use schema-version-aware lazy-column detection so rolled-back first-use assignments cannot poison later writes. Ordinary legacy JSON imports still cannot declare their own owner.

The shared ownership implementation shrinks by four lines; the complete production delta is +61/-48, net +13 lines, justified by preserving durable human assignment across every real Doctor/startup migration path. No schema version, protocol, configuration, public API, sharing authorization, or dependency changes.

User Impact

The owner shown in session lists, owner filters, and responsibility facets remains accurate after Doctor repairs, startup migration, cross-agent store moves, conflict quarantine, and malformed-session recovery. Unowned sessions stay unowned; first-use legacy databases remain readable and only gain the existing nullable owner columns when an actual assignment is preserved.

Evidence

Before the fix, real Doctor repair failed all three initial ownership cases: an owned alias kept the wrong previous destination owner, an unowned winner inherited a stale owner, and a cross-store move lost its assignment. A separate real nested transaction reproduced the poisoned schema cache as no such column: owner_actor_type; the existing conflict-quarantine flow also lost its assignment.

After the owner-boundary repair, 162 tests pass across real session assignment/rollback, legacy in-place and cross-store migration, owned/unowned quarantine, Doctor canonical/malformed/retention repair, startup, migration ledgers/races, the full SQLite accessor suite, and a forged-owner JSON import regression:

node --no-maglev node_modules/vitest/vitest.mjs run --config test/vitest/vitest.runtime-config.config.ts src/config/sessions/session-accessor.sqlite-owner.test.ts src/config/sessions/legacy-main-session-migration.test.ts
node --no-maglev node_modules/vitest/vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/commands/doctor-session-canonical-keys.owner-repair.test.ts src/commands/doctor-session-canonical-keys.test.ts src/commands/doctor-session-canonical-keys.retention.test.ts
node --no-maglev node_modules/vitest/vitest.mjs run --config test/vitest/vitest.runtime-config.config.ts src/config/sessions/session-accessor.test.ts src/config/sessions/legacy-main-session-migration.ledger.test.ts src/config/sessions/legacy-main-session-migration.startup.test.ts src/config/sessions/legacy-main-session-migration.race.test.ts

Core typecheck, type-aware lint, formatting, import-cycle validation, SQLite schema-version guard, max-lines ratchet, assertion-safety ratchet, and independent in-session code review also pass. The tests execute the real Doctor migration, real SQLite transactions, and public owner-assignment API; no external provider or authenticated channel is involved.

@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 22, 2026
@steipete
steipete merged commit 980e67e into main Aug 22, 2026
234 checks passed
@steipete
steipete deleted the codex/doctor-session-owner-repair-qa branch August 22, 2026 00:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant