Repository navigation
fix(gateway): preserve terminal task run identity - #121192
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 1:12 AM ET / 05:12 UTC. ClawSweeper reviewWhat this changesThe PR forwards Gateway loopback run identity into terminal creation and binds task-owned PTYs using both run ID and child session. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open. Current main does not contain the PR head, and the prior cross-child lookup blocker is resolved by carrying the prepared run ID and selecting the task within its child-session scope. Priority: P1 Review scores
Verification
How this fits togetherGateway MCP requests construct tools for an agent session, including terminals. The task registry later emits a terminal task transition, and Gateway cleanup closes the PTY recorded with that exact task ID. flowchart LR
A[Gateway MCP request] --> B[Prepared run identity]
B --> C[Gateway tool resolution]
C --> D[Terminal task lookup]
D --> E[Child-session task scope]
E --> F[PTY task binding]
F --> G[Terminal task cleanup]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +27, Tests +124. Total +151 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the narrow child-session projection and land it after exact-head quality checks are green; the global run-ID lookup must not regain terminal ownership responsibility. Do we have a high-confidence way to reproduce the issue? Yes—source inspection reconstructs the collision: the former global run-ID lookup could select another child session and then discard it without finding the matching task. The PR body also supplies an exact-head after-fix collision trace. Is this the best way to solve the issue? Yes—the fix preserves the prepared Gateway fact and resolves ownership at the task-registry scope that owns child-session identity, rather than adding a terminal-side fallback or changing unrelated detached-task behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f8fcfe34b9f4. 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 (6 earlier review cycles)
|
bea5ea5 to
105795f
Compare
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
105795f to
3b7e72f
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer proof request for exact head All exact-head CI checks are green. A synthetic merge into current upstream Please run one maintainer Testbox/Crabbox harness through the real chain: |
…21192) Punchcard-Session: calm-workshop-cedar-hx
Related: #121070
What Problem This Solves
Fixes an issue where a terminal opened through the Gateway MCP loopback could survive its task's completion when another child session had a task with the same run ID.
Gateway tool resolution dropped the prepared run ID. Forwarding it exposed a second issue: terminal ownership used the registry's global preferred run-ID match, then discarded a mismatched child session without searching the correct scope.
Why This Change Was Made
The Gateway now forwards its existing prepared
runId. Terminal ownership resolves the task through the canonical task-registry scope{ runId, childSessionKey }, then records the exact private task ID used by lifecycle cleanup.This is the complete owner-boundary repair. It adds no config, protocol, SDK, migration, persistence, identity, fallback, or cache surface. The detached-task runtime retains its existing global lookup because it has a different ownership contract.
This change was developed with AI assistance and rewritten by a maintainer after ClawSweeper found the cross-child collision.
User Impact
Completing one Gateway/loopback task now closes that task's PTY even when another child session reuses the same run ID. The sibling task's terminal remains live and writable.
Evidence
shared-run; the new duplicate-run-ID test failed because the child session was absent. After the rewrite, both terminal and Gateway regressions pass and assert lookup by("shared-run", childSessionKey).terminal-tool, Gateway resolver/exclusion, terminal session lifecycle, runtime subscriptions, task status access, and the two registry cross-scope collision cases.tbx_01kzwqhv8vfftahjzk8tj8thq4, run https://github.com/openclaw/openclaw/actions/runs/31668517679, completed with exit 0. Core production/test typechecks, changed-file lint/format, import-cycle, dead-code, database-first, SDK, and repository guards passed..agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex --model gpt-5.6-sol --thinking high --stream-engine-outputreported no accepted/actionable findings; overall correctness 0.98.git diff --checkpassed.Exact-head MCP-to-real-PTY collision proof
Exact commit:
ae68f2d4e2f8b659af6c7754aa74eed1fced3246The transient harness traversed real loopback HTTP
/mcp-> bound shared-run grant -> production Gateway resolver -> production terminal tool -> real@lydell/node-pty-> production task-registry observer cleanup.It deliberately created two tasks with the same run ID in different child sessions. Task 1 was the registry's global preferred match, so the pre-rewrite lookup would leave task 2's terminal unbound. On the rewritten head, terminalizing task 2 reduced live PTYs from two to one; task 1 stayed writable and emitted output after cleanup.
Harness SHA-256:
fc8842e6788a2ee81a9f148f1eb218395927f2917ad05e46a2231fc14aad03d6Verdict SHA-256:
49aafa97112e9d068de81f70fee9697342318ff8e56b9b3c761bebc8c74bc752{ "schemaVersion": 1, "verdict": "pass", "targetSha": "ae68f2d4e2f8b659af6c7754aa74eed1fced3246", "boundary": [ "real-loopback-http-/mcp", "bound-runId-grant", "production-gateway-tool-resolver", "production-terminal-tool", "real-node-pty", "production-task-registry-observer-cleanup" ], "assertions": { "exactGrantPublishedOnlyTerminal": true, "duplicateRunIdAcrossChildSessions": true, "globalPreferredTaskBelongsToOtherChild": true, "distinctRealPtyProcesses": true, "completedTaskTerminalClosed": true, "siblingTerminalRemainedWritable": true, "siblingOutputObservedAfterCleanup": true }, "observations": { "httpStatus": 200, "taskCount": 2, "ptyProcessCount": 2, "sessionCountBeforeCleanup": 2, "sessionCountAfterCleanup": 1, "capturedTerminalCalls": 7, "emittedTerminalEvents": 0 }, "redaction": { "bearerTokensIncluded": false, "filesystemPathsIncluded": false, "terminalOutputIncluded": false } }The earlier Linux public proof remains available at https://github.com/Alix-007/openclaw/actions/runs/31376607923 and establishes the same production MCP-to-PTY boundary on the contributor branch before the collision rewrite.
Dependency contract
Direct sibling Codex inspection on commit
414782450952a196bbb64b1605a458c2531c47b6:codex-rs/core/src/session/mcp.rs:292-303forwards server, tool, arguments, and request metadata into the MCP manager.codex-rs/core/src/mcp_tool_call.rs:576-607adds Codex thread/sandbox/trace metadata, but carries no OpenClaw task-row identity.codex-rs/core/src/session/mod.rs:3267-3276shows the same MCP call contract.Therefore OpenClaw must preserve the prepared run ID at tool construction and resolve its own exact child-session task scope.
Scope
The positive production delta is the canonical scoped status projection needed to enforce the task-ownership boundary. No changelog entry is included because contributor PRs leave changelog updates to the landing workflow.
Punchcard-Session: calm-workshop-cedar-hx