Skip to content

fix(copilot): read the real permission and background-work signals - #17

Merged
nplez1 merged 1 commit into
nplez1/mainfrom
nplez1/Copilot-Auto-Approval-Issue
Sep 22, 2026
Merged

nplez1 merged 1 commit into
nplez1/mainfrom
nplez1/Copilot-Auto-Approval-Issue

Conversation

@nplez1

@nplez1 nplez1 commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​820 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​785
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​348 $\color{#cf222e}{\Huge{\mathbf{−}}}$​83 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​265

ELI5

When Orca runs the GitHub Copilot CLI, it reads Copilot's hook events to decide what an agent pane is
doing. Two of those readings were wrong: Orca raised "Needs attention" for permission checks Copilot
had already allowed by itself, and its "background work" tracker disagreed with whether Copilot was
still busy. This teaches Orca to read the events Copilot actually sends, so a pane shows Working
while Copilot is working and only asks for attention when something is really waiting on you.

What Changed

Before, on a Copilot pane:

  • An auto-approved permission check (/allow-all, --yolo, an allowed path) could flip the pane to
    "Needs attention" until the next prompt, because Orca blocked on Copilot's async
    permission_prompt notification even when no prompt was shown.
  • "Monitoring background tasks" could show while the agent was mid-turn, and fail to show while a
    background shell or subagent was running, because the tracker matched field names Copilot never
    sends (background, runInBackground, run_in_background) and counted every task call as
    background work.
  • A subagent's own prompt/tool/Stop events were applied to the lead pane (subagents arrive on the
    same pane carrying their own session id), so a subagent could replace the lead's prompt or mark the
    pane done.
  • A background shell the agent read to completion with read_bash never cleared, because Copilot
    suppresses shell_completed in that case, stranding the pane in monitoring.

After: Orca reads the signals Copilot CLI 1.0.87 actually sends, matches shells and subagents by
identity, and keeps the pane Working until the last outstanding item settles.

Mechanism:

  • Permission: a permission_prompt notification no longer blocks once a tool has completed since
    the request (positive evidence the prompt was never shown); an absent snapshot still blocks, so a
    real prompt is never hidden. Also recognises the real camelCase permissionRequest payload
    (hookName), which was otherwise misread as a PreToolUse.
  • Background shells: registered from the start result
    (<command started in background with shellId: N>), so an async shell that finishes within
    initial_wait (which returns inline) is never tracked; settled by the
    shell_completed/shell_detached_completed notification or by any result that proves the shell
    stopped (read_bash/stop_bash). Matching is by shellId, so one shell's completion cannot
    consume another.
  • Subagents: only task/agent with mode:"background" counts (sync tasks leaked a count);
    SubagentStart/SubagentStop and agent_completed consume an identity-aware count and never
    touch pending shells, so a redundant agent completion cannot settle one.
  • Subagent events: any event whose session id differs from the pane's lead session id is
    child-scoped — it may contribute background work, but cannot change the pane's prompt, tool, or
    state, or settle it.

Why

The previous branch (fix/copilot-background-work) inferred Copilot's signal names rather than
reading them. Capturing live hook payloads from Copilot CLI 1.0.87 showed that every shell field it
matched was invented, that the task tool is mode:"sync"|"background", that a background shell can
be read to completion (suppressing the notification), and that a subagent runs as its own session on
the lead pane. Dropping the permission_prompt signal outright also regressed real prompts, so the
permission fix keeps blocking but adds the "resolved without the user" evidence instead of removing
the signal.

Linked Issue

Fixes stablyai#19780
Fixes stablyai#20810

Visual Proof

N/A — this changes no layout or new UI. It corrects which existing status a Copilot pane shows:
"Needs attention" becomes Working for auto-approved permission checks, and Working (monitoring) is
held until background shells/subagents settle instead of flipping to Done.

Testing

  • pnpm tc (all typecheck projects), pnpm run check:code-quality:changed, targeted oxlint.

  • 1,300 tests across src/main/agent-hooks + src/shared/agent-hook-listener.

  • New tests: child-session attribution (including two nesting levels), shell identity tracking
    (a subagent shell vs the lead's, unknown completion ignored, redundant agent completion), inline-
    async and read-to-completion shells, permission-notification staleness, and a replay of a real
    Copilot CLI 1.0.87 nested background capture saved under src/main/agent-hooks/__fixtures__/.

  • Manual: exercised a real Copilot CLI 1.0.87 on macOS (nested background subagents plus an async
    shell read to completion). No Linux/Windows-specific code paths were touched.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with DeepSeek V4.1 Flash in the Pi coding agent harness; the author reviewed the diff and ran
the tests.

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

Security: no new inputs or trust boundaries; parsing only handles hook payloads already authenticated
and attributed to a pane. Cross-platform: no OS-specific code. SSH/remote: the change is in the
shared hook listener used by main and the relay, so remote panes get the same behavior. Backwards
compatibility: older fields are not required; a missing signal still blocks a permission prompt and
still leaves a shell untracked rather than stranding it.

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) — ran pnpm tc, the changed-code gate, and the affected suites locally; CI covers the full suite/build.

Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
@nplez1
nplez1 merged commit e8ac2f6 into nplez1/main Sep 22, 2026
36 checks passed
nplez1 added a commit that referenced this pull request Sep 22, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
nplez1 added a commit that referenced this pull request Sep 25, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
nplez1 added a commit that referenced this pull request Sep 27, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
nplez1 added a commit that referenced this pull request Sep 29, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
nplez1 added a commit that referenced this pull request Oct 1, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
nplez1 added a commit that referenced this pull request Oct 6, 2026
Follow-up to fix/copilot-background-work, verified against live Copilot CLI
1.0.87 hook captures rather than inferred field names.

- Permission: a permission_prompt notification no longer blocks once a tool
  completed since the request (it was auto-approved), while an absent snapshot
  still blocks so a real prompt is never hidden; also recognise the real
  camelCase permissionRequest payload, which was misread as a PreToolUse.
- Background shells: match mode:"async"/detach:true instead of the invented
  background/runInBackground/run_in_background fields, register from the start
  result so an inline-completing async shell is never tracked, and settle on
  the shell_completed notification or a read_bash/stop_bash result. Matching is
  by shellId so one shell's completion cannot consume another.
- Subagents: count only task/agent with mode:"background" (sync tasks leaked a
  count and pinned monitoring); consume agent_completed/SubagentStop by an
  identity-aware count that never touches pending shells.
- Attribute a subagent's own session events to the child, not the lead pane,
  so they cannot replace the lead's prompt/tool or settle it.

Fixes stablyai#19780
Fixes stablyai#20810
@nplez1
nplez1 deleted the nplez1/Copilot-Auto-Approval-Issue branch October 24, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant