Skip to content

fix(agent-status): stop an auto-reviewed Codex approval reading as "Needs You" - #21389

Merged
brennanb2025 merged 5 commits into
mainfrom
brennan/sta-7698-bug-agent-goes-back-and-forth-between-needs-you-and-working
Sep 18, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennan/sta-7698-bug-agent-goes-back-and-forth-between-needs-you-and-working

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​232 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​232
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​308 $\color{#cf222e}{\Huge{\mathbf{−}}}$​113 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195

ELI5

When you run Codex in Orca on its "Approve for me" setting, Codex asks a helper to
approve each command instead of asking you. Orca was treating that request as if it
were aimed at you, so the agent's label kept blinking between "Working" and "Needs
You" and you got a notification each time — while nothing was actually waiting on you.
Now Orca checks who the request was addressed to, and only says "Needs You" when the
answer is you.

What Changed

Before: a Codex agent on "Approve for me", given one ongoing task, flipped between
"Working" and "Needs You" several times a minute, with a desktop notification and a
badge on each flip. Nothing needed a human. People muted agent notifications and then
missed the real ones.

After: the label stays "Working" for the whole turn. A real approval — where Codex
is genuinely waiting on you — still shows "Needs You" exactly as before.

Mechanism. Codex's PermissionRequest hook runs as the first decider in its
approval chain, ahead of both its own review agent and the user. So the event means "a
decision is being made", not "a human is blocked" — and Orca was mapping it straight to
a waiting state with no qualification.

The execution host now reads the turn's approvals_reviewer and keeps a
reviewer-owned approval as working. It reads it off the session rollout Orca already
tails incrementally for subagent reconciliation, from the same turn_context record it
already parses for the child model — so there is no new file I/O, no new polling, and no
new store. The decision happens once, at write time, on the host that owns the process,
so every reader (sidebar, worktree ps, mobile, dashboard) gets the same answer.

request_user_input is deliberately untouched: it arrives as a PreToolUse and no
reviewer can answer a question addressed to the user.

Why

Positive evidence only, so it cannot hide a real prompt. An absent field, an older
Codex build, or an unreadable rollout all still raise the wait — that is the pre-existing
behaviour. The change can only ever turn a false "Needs You" into "Working".

Alternatives considered and rejected:

  • A longer quiet window. One already ships at 1.5s and only ever gated the
    notification, never the label. Reporters measured auto-reviews at 3s and 20s, and a
    person can answer in under a second, so no fixed delay separates the two cases.
  • Reading the permission_mode field already on the hook payload. It only
    distinguishes Codex's "Full Access"; "Approve for me" is a separate reviewer setting,
    so the reported sessions report the ordinary value and the bug would survive.
  • Ignoring the approval event entirely. This would fix the flapping but make a
    genuine approval invisible in Manual mode, which Orca supports.
  • Inferring the mode from the launch arguments, which is what the existing
    suppression does. It compares the whole arguments string for an exact match, so it
    misses a mode changed inside the session (the reported case), extra flags alongside the
    right one, settings in config.toml, and any pane Orca did not launch itself.

Also splits the incremental rollout JSONL cursor into its own module. The new reader put
codex-subagent-transcript.ts over the file-length cap, and the cursor is a
self-contained concern already shared by the parent and child readers.

Linked Issue

Fixes #21051

Visual Proof

One frame, both cases, driven through the real hook server in a dev instance on this branch:

sta7698-proof-side-by-side.png

  • Tab 1, "Codex - action required" — a pane sent an approval whose turn names the user as
    reviewer. It still raises the attention title, exactly as before. This is also what the pane
    looked like on every approval before this change
    , because the reviewer was never consulted.
  • Tab 2, "Terminal 2" — a fresh pane sent three gated tool calls in one turn, all with the turn
    naming the auto-reviewer. Plain title, no attention marker, no unread badge.

Backing state read from the renderer store for tab 2 after the turn:

rowState: "working"            // never entered waiting on any of the three approvals
syntheticTitleEverInjected: null   // the "Codex - action required" title was never sent
unreadThisTab: false
unreadAgentCompletionPanes: 0

That last line matters: because the row never reaches a waiting state, the synthetic attention
title and its trailing bell are never injected either, so the second notification path this bug
also drove goes quiet without being touched.

Testing

New suite src/shared/agent-hook-listener-codex-approval-ownership.test.ts (8 cases):
a reviewer-owned approval reads as working; a user-owned one still waits; an absent
reviewer, an unreadable rollout, and a missing transcript path all still wait;
request_user_input still waits under auto review; one session's reviewer does not leak
into the next rollout; and a full turn never flaps.

Ablation: disabling the single qualifier fails exactly the 3 behaviour cases while the 5
no-hiding guards keep passing, so the suite discriminates rather than passing trivially.

Regression: the related existing suites pass unchanged — subagent transcript, the
codex/hermes/droid listener suite, startless child lifecycle, interactive prompts,
extraction characterization, and relay hook integration (68 tests total).

Gates: pnpm tc, oxlint, and pnpm run check:code-quality:changed all clean.

Platforms: logic is platform-neutral and lives in the shared normalizer that both the
local hook server and the SSH relay call, so a remote host reads its own rollout — which
is the only host that can. Verified on macOS; not yet exercised on Windows or Linux, and
the SSH path is covered by the relay suite rather than a live run.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Backwards compatibility: the reviewer field is optional and absence preserves today's
behaviour, so older Codex builds are unaffected. No wire change — the status row keeps
its shape and vocabulary, so mixed-version paired clients see no difference. Performance:
no new reads, no new polling, no new subprocess; the rollout records were already being
parsed in the same loop. Security: reads only a file Codex itself wrote inside the home
Orca manages.

Related but deliberately out of scope: the same class affects Copilot /allow-all
(#19780) and OpenCode Auto (#18950), each with one report; and the terminal-title
heuristic matches "permission" and "waiting" as raw substrings, which is a separate
mechanism with its own report.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…eeds You"

Codex runs its PermissionRequest hook as decider #1, ahead of both its own
review agent and the user, so the event means "a decision is being made", not
"a human is blocked". Under the "Approve for me" posture the review agent
resolves it seconds later, so every gated tool call drove the pane from Working
to Needs You and back, plus a desktop notification each time.

The execution host now reads the turn's approvals_reviewer off the rollout it
already tails for subagent reconciliation, and keeps a reviewer-owned approval
as working. Positive evidence only: an absent field, an older rollout, or an
unreadable file all still raise the wait, so this can never hide a real prompt.

Splits the incremental rollout JSONL cursor out of the subagent transcript
module, which the new reader pushed over the file-length cap.
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 223fc255-c377-4ec0-bc32-3d3d94063864

📥 Commits

Reviewing files that changed from the base of the PR and between f958f68 and ecaaf20.

📒 Files selected for processing (4)
  • src/shared/agent-hook-listener-codex-approval-ownership.test.ts
  • src/shared/agent-hook-listener/providers/codex-events.ts
  • src/shared/codex-subagent-reviewer.ts
  • src/shared/codex-subagent-transcript.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The change adds incremental Codex rollout JSONL readers and tracks reviewer ownership by transcript path. PermissionRequest events resolve to working for auto-reviewed transcripts and to waiting otherwise. The logic applies to lead and child events. request_user_input remains waiting. Tests cover reviewer changes, missing or unreadable rollouts, relay restarts, session isolation, and complete auto-reviewed turns.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to ecaaf

After a transient rollout-file read failure, restored auto-reviewed approvals can incorrectly show “Needs You” until the transcript changes. This is a bounded UI regression; merge is acceptable with owner awareness.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing auto-reviewed Codex approvals from being shown as requiring user attention.
Description check ✅ Passed The description is complete and well aligned with the template. It includes the user impact, mechanism, rationale, linked issue, visual proof, testing details, compatibility notes, and completed check…
Linked Issues check ✅ Passed Issue #21051 requires Codex approval handling that does not show a false "Needs You" state during automatic review. The change reads approvals_reviewer from rollout data, maps legacy `guardian_subag…
Out of Scope Changes check ✅ Passed The changes stay within Issue #21051. The JSONL cursor, reviewer reconciliation, transcript-path scoping, state classification, and regression tests support the required distinction between reviewer-o…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Reconcile child transcripts before resolving approval ownership. · codex-events.ts:160-175

src/shared/agent-hook-listener/providers/codex-events.ts:160-175
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reconcile child transcripts before resolving approval ownership. Codex permits PermissionRequest hooks in thread-spawned subagents and supplies agent_id and transcript_path. If a child request arrives before the lead event reconciles the current rollout, this branch resolves ownership from stale cached reviewer state and can classify an auto_review approval as waiting. Reconcile the event transcript before resolving childState.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 6a557819-0897-4fd3-b78c-7051edf504ab

📥 Commits

Reviewing files that changed from the base of the PR and between 71f3bdb and bd37f0f.

📒 Files selected for processing (5)
  • src/shared/agent-hook-listener-codex-approval-ownership.test.ts
  • src/shared/agent-hook-listener/providers/codex-events.ts
  • src/shared/agent-hook-listener/providers/codex-state.ts
  • src/shared/codex-rollout-jsonl-cursor.ts
  • src/shared/codex-subagent-transcript.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

}
} else {
const leadState = codexLeadStateForHookEvent(eventName)
const leadState = codexLeadStateForHookEvent(eventName, payload.state)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

sed -n '140,225p' src/shared/agent-hook-listener/providers/codex-events.ts
sed -n '60,145p' src/shared/agent-hook-listener/providers/codex-state.ts
sed -n '1,130p' src/shared/codex-subagent-roster.ts
rg -n 'reconcileRemoteCodexState|codexRosterEffectiveState|leadState' src/shared --glob '*.ts'

Repository: stablyai/orca

Length of output: 11990


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- codex-subagent-roster.ts ---'
sed -n '118,150p' src/shared/codex-subagent-roster.ts
printf '%s\n' '--- codex-events.ts ---'
sed -n '1,90p' src/shared/agent-hook-listener/providers/codex-events.ts
sed -n '188,220p' src/shared/agent-hook-listener/providers/codex-events.ts
printf '%s\n' '--- codex-state.ts ---'
sed -n '1,180p' src/shared/agent-hook-listener/providers/codex-state.ts
printf '%s\n' '--- direct bindings and payload definitions ---'
rg -n -C 3 'reconcileRemoteCodexState|buildCodexStatusPayload|buildCodexChildDrivenStatusPayload|ParsedAgentStatusPayload|codexLeadStateByPaneKey' src/shared --glob '*.ts'

Repository: stablyai/orca

Length of output: 50369


Keep the normalized lead state separate from the aggregate payload state.

When the lead is working and a child is waiting, codexRosterEffectiveState makes the transmitted payload.state waiting. reconcileRemoteCodexState then passes that aggregate value to codexLeadStateForHookEvent, which stores waiting as the lead state. A later SubagentStop only removes the child and recomputes the aggregate, so the lead remains waiting.

Carry the normalized lead state as separate transport metadata and use it for lead reconciliation.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — the mechanism is sound and I verified the upstream Codex contract it depends on. One remote-path coverage gap is worth closing before merge.

Reviewed changes

  • Host-side approval ownership — resolveCodexApprovalOwnedState in codex-events.ts downgrades a PermissionRequest wait to working when the turn's reviewer is auto_review, for both lead and agent_id events.
  • Reviewer retention — CodexSubagentTranscriptState.approvalsReviewer is read from the parent rollout's turn_context and retained across incremental reads, reset only when the rollout path changes; codexTurnApprovalsAreAutoReviewed exposes it.
  • Relay pass-through — codexLeadStateForHookEvent now accepts the normalized payload state so a relayed reviewer-owned approval stays working instead of being re-derived as waiting.
  • Cursor extraction — JSONL cursor/record/directory helpers moved into src/shared/codex-rollout-jsonl-cursor.ts.
  • Tests — new 8-case suite covering auto/user/absent/unreadable/no-path/request_user_input/cross-rollout/no-flap.

I confirmed against upstream openai/codex that turn_context.payload.approvals_reviewer is real, serializes as exactly "user" / "auto_review", is written unconditionally when a turn_context record is emitted, and that a reviewer switch forces a fresh turn_context — so the ?? state.approvalsReviewer retention cannot leave a stale auto_review after a switch back to manual.

ℹ️ The relay path's new pass-through is untested

The codexLeadStateForHookEvent(eventName, payload.state) change is the only thing that keeps a reviewer-owned approval working on a remote/SSH pane, and no test drives it. The PR body's claim that "the SSH path is covered by the relay suite rather than a live run" is not currently true — the relay suites are Claude-only and the codex ingestRemote cases cover working/done/child identity, never a lead PermissionRequest.

Technical details
# relay-path-pass-through

## Affected sites
- `src/shared/agent-hook-listener/providers/codex-state.ts:127` — `codexLeadStateForHookEvent(eventName, payload.state)` decides `working` vs `waiting` for relayed codex approvals; no test reaches it with `eventName === 'PermissionRequest'`.
- `src/main/agent-hooks/server-ingest-remote.test.ts` / `src/main/agent-hooks/server-relay-listener-replay.test.ts` — codex cases exist but none ingest a codex lead `PermissionRequest`.

## Required outcome
- A `connectionId`-stamped codex lead `PermissionRequest` with `payload.state: 'working'` stays `working` through `reconcileRemoteCodexState`.
- The same event with `payload.state: 'waiting'` stays `waiting` (older-host / genuine-prompt case).

## Suggested approach
- Add an `ingestRemote` case asserting the snapshot state for both payload states, mirroring the existing remote codex cases.

ℹ️ Nitpicks

  • readApprovalsReviewer's doc (src/shared/codex-subagent-transcript.ts:149) says the field is absent "whenever Codex resolves the field to nothing". Upstream builds turn_context with approvals_reviewer: Some(...) unconditionally, so a written record always carries "user" or "auto_review"; only genuinely older rollouts omit it. Worth tightening so the comment doesn't imply a case that can't occur.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 7d21e4a2-3aea-4ead-a908-49be09c7f41d

📥 Commits

Reviewing files that changed from the base of the PR and between bd37f0f and d694b08.

📒 Files selected for processing (2)
  • src/shared/agent-hook-listener-codex-approval-ownership.test.ts
  • src/shared/codex-subagent-transcript.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +235 to +237
parentRecords === undefined
? undefined
: (readApprovalsReviewer(parentRecords) ?? state.approvalsReviewer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset the parent cursor after an unreadable read.

If a read fails after the cursor reaches EOF, this branch clears approvalsReviewer but retains state.parent.offset. If the file becomes readable again without a size change, readJsonlCursor returns no records. The reviewer is not restored, so later auto-reviewed PermissionRequest events remain waiting for the rollout.

Reset offset and carry when the read is unreadable. Add a regression test that removes and restores the same rollout file.

Proposed fix
-  state.approvalsReviewer =
-    parentRecords === undefined
-      ? undefined
-      : (readApprovalsReviewer(parentRecords) ?? state.approvalsReviewer)
+  if (parentRecords === undefined) {
+    state.approvalsReviewer = undefined
+    state.parent.offset = 0
+    state.parent.carry = ''
+  } else {
+    state.approvalsReviewer = readApprovalsReviewer(parentRecords) ?? state.approvalsReviewer
+  }

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run reviewed the delta since the prior pullfrog review (bd37f0f → d694b08), which hardens the reviewer read and closes the prior inline coverage gap.

  • Thread-settings reviewer switch — readApprovalsReviewer now also reads event_msg/thread_settings_applied.thread_settings.approvals_reviewer, so switching "Approve for me" back to manual mid-session re-raises the wait instead of retaining auto_review.
  • Unreadable rollout clears the retained reviewer — when readJsonlCursor cannot read the parent rollout, approvalsReviewer is reset rather than carried, so a stale auto_review cannot hide a genuine prompt.
  • Legacy alias — guardian_subagent maps to auto_review, matching Codex's deserialize alias.
  • Tests — three new cases pin the reviewer switch, the legacy alias, and the unreadable-rollout reset.

I verified the new record shape against upstream openai/codex main: ThreadSettingsApplied(ThreadSettingsAppliedEvent) carries thread_settings: ThreadSettingsSnapshot with a required approvals_reviewer, and ApprovalsReviewer serializes auto_review while accepting guardian_subagent only as a deserialize alias. The suite (11 tests) passes, as do the 106 agent-hooks/agent-hook-listener files; check:code-quality:changed reports 0 new findings.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a39edf62-70a1-4a89-9e3a-01356da03a50

📥 Commits

Reviewing files that changed from the base of the PR and between d694b08 and f958f68.

📒 Files selected for processing (3)
  • src/shared/agent-hook-listener-codex-approval-ownership.test.ts
  • src/shared/agent-hook-listener/providers/codex-events.ts
  • src/shared/codex-subagent-transcript.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Comment thread src/shared/codex-subagent-transcript.ts Outdated
state.approvalsReviewer = undefined
return
}
state.approvalsReviewer = readApprovalsReviewer(records) ?? state.approvalsReviewer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

sed -n '140,215p' src/shared/agent-hook-listener/providers/codex-events.ts
sed -n '220,345p' src/shared/codex-subagent-transcript.ts
rg -n 'approvalsReviewer|reconcileCodexSubagentReviewer|codexTurnApprovalsAreAutoReviewed|mixed parent|child.*reviewer' src/shared --glob '*.ts'

Repository: stablyai/orca

Length of output: 9449


🏁 Script executed:

sed -n '1,215p' src/shared/codex-subagent-transcript.ts
sed -n '215,355p' src/shared/codex-subagent-transcript.ts
sed -n '100,215p' src/shared/agent-hook-listener/providers/codex-events.ts
sed -n '1,180p' src/shared/agent-hook-listener-codex-approval-ownership.test.ts 2>/dev/null || true
rg -n 'resolveCodexApprovalOwnedState|readApprovalsReviewer|reviewerCursorsByPath|approvalsReviewer' src/shared --glob '*.ts'

Repository: stablyai/orca

Length of output: 25006


🏁 Script executed:

sed -n '1,215p' src/shared/codex-subagent-transcript.ts
sed -n '100,215p' src/shared/agent-hook-listener/providers/codex-events.ts
rg -n -A35 -B15 'resolveCodexApprovalOwnedState|codexTurnApprovalsAreAutoReviewed|readApprovalsReviewer' src/shared --glob '*.ts'
rg -n -A80 -B15 'child-first manual approval|approval ownership|auto_review|user' src/shared/agent-hook-listener-codex-approval-ownership.test.ts src/shared --glob '*test.ts' 2>/dev/null

Repository: stablyai/orca

Length of output: 50370


Scope approval reviewers to their rollout path.

reconcileCodexSubagentReviewer stores a child reviewer in the shared state.approvalsReviewer. When the next parent PermissionRequest has no new parent reviewer record, parent reconciliation retains that child value through the nullish fallback. The parent-path reset does not run because the parent path has not changed.

A child auto_review value can therefore classify a later parent approval as working and hide a user-owned prompt. The inverse case can show an auto-reviewed child as waiting.

Store reviewer state by normalized rollout path, including the parent path. Resolve the reviewer for the current event's transcript path. Add a mixed parent-and-child reviewer regression test.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Attachments

Electron visible proof — PR #21389

pr-21389-electron-orca.png
pr-21389-electron-orca.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: PASS — ready to land after fixes

I completed the requested review loops on PR #21389. The review found and fixed three meaningful issues without expanding scope:

  • d694b08981: clears stale Codex reviewer ownership when settings change, legacy reviewer spelling is received, or rollout data becomes unreadable.
  • 37edc44e07: reconciles child-first Codex PermissionRequest events after relay restart, with regression coverage.
  • f958f687e2: limits reviewer transcript reads to child PermissionRequest events so ordinary child activity does not incur extra synchronous I/O.

Validation on final HEAD f958f687e2:

  • Focused status/relay tests: 6 files, 42 tests passed.
  • pnpm tc: passed.
  • pnpm run check:code-quality:changed: passed with zero new findings.
  • git diff --check: passed.
  • PR CI: all required checks passing (typecheck, static analysis, package, Windows package, E2E, SSH/hooks, and test shards).
  • Final readiness audit: PASS across all eight sections; no proven P0/P1/P2 findings.

Electron validation attached a visible screenshot to this PR after launching the exact branch worktree with CDP and verifying the app identity/branch. The requested Grok Electron worker was attempted but hit the provider's weekly usage limit, so the Electron evidence is from the fallback CDP validation.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Reading a subagent rollout's reviewer into the shared per-pane state can hide a genuine manual approval. Details inline.

Reviewed changes

This run reviewed the delta since the prior pullfrog review (d694b08 → 37edc44).

  • Child-first reviewer reconciliation — normalizeCodexEvent now reconciles a child's rollout reviewer before classifying a child PermissionRequest, so a subagent approval no longer waits on a reviewer the parent never supplied.
  • Separate reviewer cursor — reconcileCodexSubagentReviewer keeps per-path incremental cursors (reviewerCursorsByPath, bounded at 64) so reading a child rollout does not consume the parent lifecycle cursor.
  • Tests — two child-first cases pin auto_review → working and user → waiting.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/shared/codex-subagent-transcript.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The reviewer-ownership finding from the prior review is unchanged by this delta and still reproduces; this commit only narrows when it can trigger. No new issues in the delta itself.

Reviewed changes

This run reviewed the delta since the prior pullfrog review (37edc44 → f958f687).

  • Scoped child reconciliation — normalizeCodexEvent now reconciles a child's rollout reviewer only for PermissionRequest, so PreToolUse/PostToolUse/other child activity no longer triggers a rollout read. resolveCodexApprovalOwnedState only consults the reviewer for PermissionRequest, so no approval classification changes.

The prior inline finding (src/shared/codex-subagent-transcript.ts:335) remains open: a child PermissionRequest still reads its rollout's reviewer into the shared per-pane state.approvalsReviewer, so a child spawned under auto_review can make a later genuine manual lead approval read working.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review update: additional architecture fix applied

The independent architecture challenge found one more concrete lifecycle bug in the previous review result: reviewer ownership was stored once per pane while rollout cursors were transcript-path scoped. A child-first approval could therefore overwrite or clear the parent reviewer, and a later parent approval with no new parent transcript bytes could be misclassified.

Commit ecaaf208ae fixes this by scoping reviewer ownership by normalized transcript path, keeping parent ownership separate and evicting child reviewer cursors and values together. It adds regressions for manual/unavailable child rollouts followed by unchanged-parent approvals, and extracts the reviewer logic into a domain module without broadening product scope.

Final validation on ecaaf208ae:

  • Focused status/relay tests: 6 files, 44 tests passed.
  • pnpm tc: passed.
  • pnpm run check:code-quality:changed: passed with zero new findings across 6 changed files.
  • Final readiness audit: PASS across all eight sections; no proven P0/P1/P2 findings.
  • Existing PR CI remains green; the earlier Electron visible-proof screenshot remains attached to this PR.

The unrelated pnpm-lock.yaml working-tree change remains untouched. The Grok Electron worker was blocked by the provider's weekly usage limit; fallback CDP validation succeeded and verified the exact branch identity.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final CI update

All GitHub-required checks for ecaaf208ae are now green, including all eight Node 24 test shards, typecheck, static analysis, macOS/Windows packaging, E2E, and SSH/hooks validation. The only remaining external status is Pullfrog, which is still pending; there are no failing checks.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run reviewed the delta since the prior pullfrog review (f958f687 → ecaaf20), which closes the prior child-reviewer clobber finding.

  • Per-path reviewer state — codex-subagent-reviewer.ts (new) keeps the parent rollout's reviewer in state.approvalsReviewer and each child rollout's reviewer in state.reviewersByPath keyed by its normalized path.
  • Path-based resolution — codexTurnApprovalsAreAutoReviewed(state, transcriptPath) reads the parent reviewer only when the event's path equals state.parent.filePath, otherwise the child's per-path entry.
  • Child reconcile no longer clobbers — reconcileCodexSubagentReviewer writes and deletes only its own path's cursor and reviewer; an unreadable child no longer clears the parent's reviewer.
  • Routing — normalizeCodexEvent sends a child PermissionRequest whose path equals the parent rollout to the parent reconcile, and every other child rollout path to the reviewer reconcile.
  • Regression tests — two new cases pin the parent reviewer surviving both a different-reviewer child and an unavailable child rollout.

I verified the prior [!IMPORTANT] finding is resolved: a child spawned under auto_review can no longer make a later genuine manual lead approval read working. The suite passes (15 tests), and pnpm run check:code-quality:changed reports 0 new findings across the 6 changed files. An independent re-check of the reviewer-state lifecycle found no reachable sequence that reproduces the old clobber.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit 66e0847 into main Sep 18, 2026
34 checks passed
@brennanb2025

Copy link
Copy Markdown
Contributor Author

@jennmueng this should fix the issue you reported:

I seem to get consistently pinged for permission requests from Orca with Codex when I'm running in auto mode. (There is no permission request from Codex)

You were right that there was no permission request from Codex. Codex asks its hooks about an approval before deciding who resolves it — ahead of both its own automatic reviewer and you. Orca was treating that as "a human is blocked", so on every gated tool call it raised a needs-input state and pinged you, and then cleared it a few seconds later when the reviewer approved.

Orca now reads which reviewer owns the turn and keeps a reviewer-owned approval as ongoing work. Because the pane never enters a needs-input state, the notification never fires — and neither does the second path this bug drove, where Orca wrote an "action required" title back into the terminal along with a bell. A real approval that genuinely waits on you is untouched and still notifies.

One thing that would help confirm we've covered your exact setup: by "auto mode", do you mean Codex's "Approve for me" reviewer, or the Default permission preset? They're separate settings, and the fix keys on the former. If you had approvals_reviewer = "auto_review" in your ~/.codex/config.toml, or launched with --approve-for-me, that's the case this addresses.

Thanks for the report — it was the clearest description of the mechanism we had.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Reproduced the phantom from real Codex, which this PR was merged without. Recording it here for the ticket trail.

The trigger wasn't where I first looked. safety.rs:69-84: a patch touching a path outside the sandbox's writable roots under approval_policy = "on-request" returns AskUser, which becomes NeedsApproval and fires the hook. Under never the same patch is rejected instead — which is exactly why anyone launching with the bypass flag never sees this bug.

Two earlier attempts failed for findable reasons worth writing down: echo and curl never reach the approval gate at all, and a patch targeting /tmp is auto-approved because /tmp is writable under workspace-write (exclude_slash_tmp defaults to false).

With the target moved outside the writable roots, real Codex 0.155.0 under on-request + workspace-write + approvals_reviewer = "auto_review":

12:17:52  SessionStart
12:17:52  UserPromptSubmit
12:17:56  PreToolUse         tool=Bash
12:17:56  PostToolUse        tool=Bash
12:18:00  PreToolUse         tool=apply_patch
12:18:00  PermissionRequest  tool=apply_patch   <-- the phantom
12:18:03  PostToolUse        tool=apply_patch
12:18:05  Stop

PermissionRequest at 12:18:00, PostToolUse three seconds later, and the file was modified. The run was non-interactive with stdin from /dev/null, so no human could have approved it. That three-second gap matches the auto-review timing measured independently on the older report.

The captured payload also rules out the simpler fix. It carried permission_mode: "default" — so reading that field, which was the obvious candidate, would have left this bug completely intact. "Approve for me" is a separate reviewer axis, not an approval policy. The payload's transcript_path pointed at a rollout whose turn_context carried approvals_reviewer: "auto_review", which is what this change reads.

Before/after on that exact captured event, replayed through the merged normalizer with its real rollout:

merged reviewer-ownership check resulting agent status
enabled working
ablated waiting — i.e. "Needs You"

The ablation used a counted substitution that asserts exactly one match, so a stale anchor fails loudly instead of passing as a false green — which it did once here, and caught it.

Verification gap, stated plainly: the rendered-UI check I ran earlier was against my original commit, before the four follow-up commits that added the per-transcript reviewer scoping. What is verified on the merged code is the normalizer path against the real captured event, plus the committed suites and typecheck. The rendered chip has not been re-checked against what actually shipped.

@jennmueng

Copy link
Copy Markdown

Lovely. and yeah I meant the "approve for me" mode. Thanks @brennanb2025 !

brennanb2025 added a commit that referenced this pull request Sep 21, 2026
…ds (#21844)

* refactor(agent-status): drop two superseded Codex attention workarounds

Codex fires its PermissionRequest hook as decider #1, before its own
auto-reviewer and before the user, so the event never meant "a human is
blocked". #21389 fixed that at the source: the execution host reads the
turn's approvals_reviewer from the rollout at write time and keeps a
reviewer-owned approval in `working`.

Two older reader-side workarounds for the same bug are now redundant.

The launch-argument suppressor guessed auto-approve mode by string-matching
the launch args, then dropped the status row in the reader. It only matched
Codex's bypass flag, and under that flag Codex's approval policy is `Never`,
which takes the Skip path and fires no PermissionRequest at all. When the
user turns on "Approve for me" inside a live session the args never change,
so it never fired for the actually-reported case either.

The Codex-only 1.5s notification quiet window could not do its job: measured
auto-reviews take 3-20s and a human can answer in under a second, so no
fixed constant separates them. Its deferred callback also re-checked
liveness and returned without notifying, so a genuine prompt whose pane went
non-live inside the window was dropped rather than delayed. Codex now
notifies synchronously like every other agent.

Also types the coordinator's completion state from the controller's exported
CompletionState instead of asserting each field, which the changed-lines
casting gate required once those lines moved.

* fix(agent-status): settle transient process-exit evidence
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.

[Bug] agent goes back and forth between "needs you" and "working" status on an ongoing task

2 participants