Skip to content

fix(agent-status): keep a nested child hook's model off the fenced parent row - #13602

Closed
brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/sta-3754-nested-model-fence
Closed

brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/sta-3754-nested-model-fence

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

When Claude runs `codex exec` (or any agent CLI nests another), the child's hooks fire on the inherited pane key. The identity fence already keeps the parent's `agentType`, but the child's model rode through the fenced payload and relabeled the parent row — a Claude session showing `gpt-5.6-sol` in the sidebar model chip — and it persisted after the child exited, because parent Claude Stop events carry no model to overwrite it back.

Fix: fence `model` beside `agentType` at both merge points —

  • `src/main/agent-hooks/server.ts`: the authoritative hook merge keeps the previous (parent) model when `inheritedFromActivePane` rewrites the agentType.
  • `src/renderer/src/store/slices/agent-status.ts`: same fence in the slice, which protects paired clients receiving payloads from an older host that lacks the main-side fence (mixed client/host versions are the normal state).

Fixes STA-3754 (parent session identity contaminated by nested delegation). The reported full icon flip is already fenced for hook agents on current main; the model chip was the remaining leak, reproduced live.

Screenshots

No visual change beyond removing the wrong model label. Live before/after evidence (dev Electron, real Claude session running real `codex exec`):

  • Before: pane entry `{agentType: "claude", model: "gpt-5.6-sol"}` persisting after turn end.
  • After (this branch): model never adopts the child's value across the same nested run.

Testing

  • `pnpm lint` (oxlint + react-doctor via pre-commit on changed files)
  • `pnpm typecheck`
  • `pnpm test` — `src/main/agent-hooks/server.test.ts` (270) and `src/renderer/src/store/slices/agent-status.test.ts` (52) all pass
  • `pnpm build`
  • Added regression tests on both sides; all four fail when the fix is reverted (verified via stash)

AI Review Report

Reviewed by the automation loop that authored it; an independent same-model Codex review round is being dispatched and its outcome will be posted as a PR comment. Risks checked: nested-hook identity fence semantics (working vs done suppression), SSH-relay root-model preservation interplay (`preservedRootModel` path is upstream of the fence and unaffected when identity is not inherited), mixed-version wire compatibility (renderer fence retained for old-host payloads), cross-platform: pure TypeScript state logic, no platform-specific behavior, no shortcuts/paths/shell involvement.

Security Audit

No input handling, command execution, path handling, auth, secrets, dependency, or IPC surface changes; the change narrows which fields of an already-accepted hook payload are merged into displayed state.

Notes

  • The nested child's transient `prompt`/`toolName` still update the row during the parent's turn (pre-existing, self-healing on the next parent event); scoped out deliberately — only `model` persists wrongly.
  • Possible follow-up: audit whether a nested child's `providerSession` metadata can contaminate the fenced row's resume identity.

…rent row

A nested child CLI (claude running codex exec) inherits the pane key, and
its hook events already have their agentType fenced to the parent identity
— but the child's model rode through and relabeled the parent row (e.g.
gpt-5.6-sol on a Claude session), persisting after the child exited
because parent Stop events carry no model.

Fence the model beside the agentType at both merge points: the main hook
server (authoritative path) and the renderer slice (protects paired
clients receiving payloads from an older host).

STA-3754
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d68ded12-1731-4fd1-9959-f13998cdbc50

📥 Commits

Reviewing files that changed from the base of the PR and between d5e1f39 and 9a6ebd2.

📒 Files selected for processing (2)
  • src/main/agent-hooks/server.test.ts
  • src/main/agent-hooks/server.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/agent-hooks/server.ts
  • src/main/agent-hooks/server.test.ts

📝 Walkthrough

Walkthrough

The change preserves the active parent agent model when nested agent events inherit the parent identity. Server normalization and renderer status updates now retain the existing model for inherited events. Tests cover active and completed parent sessions, including cases where the parent has no model.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing nested child hooks from overwriting the parent pane model.
Description check ✅ Passed The description includes all required sections, explains the fix, documents testing and security review, and clearly notes that the build remains unverified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review + QA gates complete at head 9a6ebd2.

Live repro (before, dev Electron @ main): real Claude session ran codex exec …; the pane entry became {agentType: "claude", model: "gpt-5.6-sol"} and the wrong model chip persisted on the Claude row after the child exited.

Review: same-model Codex loop (gpt-5.5 xhigh) via Orca orchestration — round 1 found the parent-completion path could still drop the preserved model in the main cache and pushed 9a6ebd2 (main-side carry-forward + test); round 2 returned clean.

Verification:

  • server.test.ts (270) + agent-status.test.ts (52) pass; all new tests fail with the fix reverted (stash-checked).
  • Typecheck, oxlint, react-doctor, changed-code quality gate pass; CI fully green, no conflicts.
  • Live re-verify on the final head: same nested codex exec run twice — pane model never adopts the child's value through working → done. Screenshots archived in ~/orca-daily-triage/sta-3754/ (final: sta3754-final-head-verified.png).
  • Perf: fix adds one conditional on the cold identity-mismatch branch of hook ingest; no hot-path or allocation change.

Linear STA-3754 moved to In Review with this PR attached. Known limit (from the clean pass): same-agent nested CLIs (claude inside claude) remain indistinguishable without a scoped signal — out of scope here.

nwparker added a commit that referenced this pull request Oct 9, 2026
Records the retained adapted contribution from #13602 in replacement PR #26846.

Co-authored-by: Brennan Benson <[email protected]>
OrcaWin pushed a commit that referenced this pull request Oct 11, 2026
Records the retained adapted contribution from #13602 in replacement PR #26846.

Co-authored-by: Brennan Benson <[email protected]>
OrcaWin pushed a commit that referenced this pull request Oct 11, 2026
* fix(agent-status): keep nested models off the parent pane

Preserve the parent's model when the existing identity fence retains an
active parent for a nested CLI hook. Exercise native SessionStart and Stop
bodies alongside model updates and legitimate pane takeovers.

Adapted from PR #25687, with real native-hook and hidden renderer proof.

Co-authored-by: Regis <[email protected]>

* chore: record original authorship for Parent-pane model ownership

Records the retained adapted contribution from #13602 in replacement PR #26846.

Co-authored-by: Brennan Benson <[email protected]>

* test: drop redundant single-agent model case

---------

Co-authored-by: Regis <[email protected]>
Co-authored-by: Brennan Benson <[email protected]>
Co-authored-by: m4air <[email protected]>
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Running another agent inside a session no longer changes the outer agent's displayed model. The replacement, including the contribution from this PR, landed in #26846.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant