Repository navigation
fix(tasks): record execution ownership and settle orphaned records at restore - #147585
Conversation
Record nullable process ownership for Gateway runs and local native harness processes. Settle confirmed dead owners through the existing restart outcome normalizer before restored tasks can block another drain. Preserve live, foreign-host, unknown, and legacy ownership. Add compatible nullable SQLite columns without changing the schema version. Reported by @gregbond (#143420).
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 13, 2026, 9:41 PM ET / September 14, 2026, 01:41 UTC (Revision 3). ClawSweeper reviewWhat this changesRecords task execution process identities in SQLite and cancels tasks with confirmed dead local owners during restore, while preserving live owners and newer linked task results. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 2 items remain This remains a distinct, useful fix for repeated restart drains. The prior flow-synchronization finding is resolved, and no blocking code findings remain. Priority: P1 Review scores
Verification
How this fits togetherThe task registry stores background-work status that Gateway restart draining consults. Gateway runs and local harness processes supply execution identity; restoration reconciles retained records before they become restart blockers. flowchart TD
A[Gateway runs and local harnesses] --> B[Capture process identity]
B --> C[SQLite task records]
C --> D[Restore and check local owner]
D -->|Dead owner confirmed| E[Persist cancelled outcome]
D -->|Live or unknown owner| F[Preserve running record]
E --> G[Update latest linked flow and drain blockers]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +204, Tests +495, Docs +28, Generated +3. Total +730 across 26 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep conservative process-based settlement and the latest-task flow guard, backed by verified release-to-candidate startup and rollback compatibility. Do we have a high-confidence way to reproduce the issue? Yes, from source: restore a recent running childless harness task after its execution process exits, then request another drain before reconciliation grace expires. This read-only review did not execute that sequence. Is this the best way to solve the issue? Yes: recording actual local process identity extends the existing registry and avoids guessing ownership for legacy or remote tasks. Upgrade validation remains necessary before landing. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a7344f3d0355. 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
HistoryReview history (2 earlier review cycles) |
Request write admission only when restored state contains a confirmed orphan, then reread and revalidate ownership before persisting settlement. Preserve existing create/delete admission-failure semantics and cover a concurrent owner rebind. List the three approved nullable ownership columns in the canonical additive schema contract test without relaxing its declaration checks.
Synchronize a restored orphan's mirrored flow only when that task is the latest linked record. Keep newer live and completed successors' status, goal, and terminal timestamps while still settling the orphaned task. Cover both mixed-owner cases through the registry restore boundary.
|
Merged via squash.
|
… restore (openclaw#147585) * fix(tasks): settle orphaned execution records at restore Record nullable process ownership for Gateway runs and local native harness processes. Settle confirmed dead owners through the existing restart outcome normalizer before restored tasks can block another drain. Preserve live, foreign-host, unknown, and legacy ownership. Add compatible nullable SQLite columns without changing the schema version. Reported by @gregbond (openclaw#143420). * fix(tasks): keep unchanged restores read-only Request write admission only when restored state contains a confirmed orphan, then reread and revalidate ownership before persisting settlement. Preserve existing create/delete admission-failure semantics and cover a concurrent owner rebind. List the three approved nullable ownership columns in the canonical additive schema contract test without relaxing its declaration checks. * fix(tasks): preserve newer flow results during restore Synchronize a restored orphan's mirrored flow only when that task is the latest linked record. Keep newer live and completed successors' status, goal, and terminal timestamps while still settling the orphaned task. Cover both mixed-owner cases through the registry restore boundary.
What Problem This Solves
Fixes #143420: after a forced Gateway drain timeout, childless native task records can remain
runningand make the successor wait through another drain even though their execution process has exited.Reported by @gregbond (#143420).
User Impact
Newly recorded tasks with a verifiably dead local execution owner become
cancelledduring restore, with the interruption reason retained, so they no longer block the next restart. Live matching owners retain existing behavior. Legacy rows, foreign hosts, remote transports, and harnesses without an available process identity retain the existing grace period, including 30 minutes for childless native tasks.Why This Change Was Made
The task lifecycle records the execution process's host, PID, and start identity. Gateway run owners record their own process; Codex native scopes use the local app-server transport PID. Connection fingerprints are not process identity. Restore reads without write admission unless an orphan is confirmed; settlement then rereads under writer custody, uses the existing terminal-outcome normalizer and retention rules, and persists before publishing restored state. Only the latest linked task can synchronize a flow, preserving newer running or successful results.
Data-model checklist: maintainer-approved additive nullable columns on
task_runs:execution_owner_host TEXT,execution_owner_pid INTEGER, andexecution_owner_start_identity INTEGER. No defaults, constraints, schema-version bump, configuration option, or sidecar. The canonical schema declares the columns; first task write ensures them idempotently; the additive migration path includes them. Read-only access does not add columns. Older compatible readers ignore these nullable columns and preserve their bytes; downgrading does not undo a recorded terminal outcome. A build predating main's existing schema-version change still requires its pre-update backup.Release-note context: prevent repeated restart drains on newly tracked native tasks whose recorded execution process exited; preserve live and unknown execution ownership.
Evidence
All proof used isolated synthetic state, without operator Gateways or authenticated providers.
drained: falseinstead oftrue. The fix returnsdrained: trueand durably recordscancelledplusTask execution process exited before restart.a7b62001c39f71e8a5d76fe7e76491ab43a0ba06.Published-driver and downgrade proof
The clean candidate was built and packed with
node scripts/package-openclaw-for-docker.mjs --source-dir "$PWD" --allow-unreleased-changelog --output-dir "$PWD/.local/l289/upgrade-proof/candidate-pack" --output-name candidate.tgz. Its embedded build commit is the head above; tarball SHA256 is391d7bf4df30ccdf05aed3d4dc042aed8cb0f6ced8829394c031e112298aa604.Using official npm packages in an isolated Linux container:
openclaw update --tag /proof/candidate.tgz --yes --no-restart --jsonreturnedstatus: okin 108,988 ms, including candidate migration rehearsal and Gateway canary.tasks show, started and cleanly stopped its Gateway, preserving the ownership and terminal-outcome bytes. Both candidate and reader used state schema 17.backup restore <archive> --target <fresh-state> --jsonsucceeded; Doctor and Gateway startup then passed with schema 16. Version markers were never lowered. These fixtures contain no agent databases, so they do not claim coverage of the separate agent-schema transition.The canonical managed first-hop cell also passed and verified the replacement service active. Its broader second-hop cell failed with
update-executor-settlement-failed/Parent executor is suspended for its candidate.and rolled the package back successfully. That path is unchanged by this PR: the child executor suspends its parent, while package Doctor calls the retained parent authority assertion. This is a separate updater follow-up, not a green result for the full canonical suite. An initial auxiliary bind-mounted npm prefix hit the shipped driver's fixed verification timeout; native container storage passed without changing timeouts.pnpm check:changedpassed all typecheck lanes, dead-code scans, and full core lint, then extension declaration preparation rejected ancestor-install discovery ofpunycode/package.jsonin the nested worktree. The guard remains intact; final hosted CI passed the isolated-checkout gates. Remaining local schema/import guards passed separately.