Skip to content

fix(agent-hooks): compare status rows structurally instead of serializing both - #23585

Merged
brennanb2025 merged 1 commit into
mainfrom
sta-7432-status-row-compare
Sep 28, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
sta-7432-status-row-compare

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​142 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​142
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

ELI5

Every time an agent reports its status, Orca checks whether anything a phone or web client can see actually changed. It did that by turning the old and new status into two long text strings and comparing them. It now compares the two values directly, stopping at the first difference, and skips the work entirely when both sides are the same object.

What Changed

Before: each status write in the main process built the published status twice and serialized both copies to JSON, including the agent's last reply (up to 8,000 characters). Older OpenCode plugins re-send the whole accumulated reply on every streamed chunk, so a long OpenCode turn paid for two full serializations per chunk.

After: the same comparison uses the existing structural-equality helper (structuralValuesEqualIgnoringUndefined). It walks the two values field by field, returns on the first difference, returns immediately for unchanged fields that share the same reference, and allocates no strings. When the caller passes the same row object on both sides it returns at once.

What counts as a change is the same as before: every field in the published status, minus the five bookkeeping fields that were already ignored (receive time, evidence time, observation, launch token, prompt interaction key). The one intended difference is that key order no longer matters, so a producer that builds the same content in a different order no longer triggers a needless republish.

Nothing the user sees changes; this is main-process CPU on the status ingest path.

Why

Two alternatives were considered and rejected:

  • Only compare the ten fields the older invalidator compared. That would regress mobile: paired clients read the whole status payload off session.tabs, so fields like sub-agents, the model, the provider session and the terminal handle genuinely need to trigger a republish.
  • Skip the comparison when nobody is listening. A listener is always installed at startup, in both the desktop app and the background daemon, so that check would never fire.

Reusing the existing structural-equality helper keeps the exact field set and fixes the cost where it comes from (serialization), with no new comparison logic.

Linked Issue

Linear: STA-7432

Visual Proof

No UI change (main-process change detection only). Live QA screenshots, before vs after, same step:

Working with a subagent row, before / after:

before-3a
after-3a

Done with the reply preview, before / after:

before-5
after-5

Testing

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

New src/main/agent-hooks/server/server-row-ownership.test.ts pins that: the same row object on both sides is unchanged; a rebuilt row with identical published content (only bookkeeping fields differ) is unchanged; the same content in a different key order is unchanged; and a change to any of state, last reply, sub-agents, a newly present payload field, state start time, connection, terminal handle, provider session or structured host still counts as a change, as does a row appearing or disappearing.

With the fix reverted, the key-order case fails and the other twelve cases still pass, which confirms the field set is unchanged.

Ran: the new test file, all of src/main/agent-hooks (105 files, 1098 passed), pnpm tc:node, pnpm exec oxlint on the changed files, and pnpm run check:code-quality:changed. Live QA (dev build on a separate Mac, before = merge base a174a086d76, after = this PR, fresh isolated profile per arm): a scripted Claude hook sequence (prompt, tool use, a subagent start/stop, tool output, stop with a 3,312-character reply, then the same stop three more times) ran inside a real Orca terminal pane through the installed hook script, while a paired-client connection subscribed to session.tabs.

  • Desktop: both arms show the same rows at every step: working, the tool name, the indented subagent row, done with the reply preview. Nothing changes on the repeated identical stops.
  • Paired client: both arms deliver a snapshot for every real change and end on done with the full reply; frame counts per step match (one step coalesced 5 events into 1 emit vs 2, same content).
  • Phone emulator: not run (the isolated host only pairs on loopback).

Not done: a CPU profile of a streaming OpenCode turn. A standalone benchmark of the compare alone measured roughly 4-7x less time per call for identical 7-8 KB rows.

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, cross-platform, SSH, mobile and mixed-version impact: none. The change is main-process only, the emitted mutation shape is unchanged, nothing is persisted, and nothing new goes over the wire. Paired clients still get a republish for every published field change.

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)

…zing both

Status-row change detection stringified two full IPC payloads on every
status write, including an up-to-8 KB lastAssistantMessage re-posted on
every OpenCode streamed part. Compare the same published field set with
the existing structural-equality helper, with a same-reference fast path.

Linear: STA-7432
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 72afff62-f6df-435d-8960-f3e8bf294c89

📥 Commits

Reviewing files that changed from the base of the PR and between a174a08 and 0adfc45.

📒 Files selected for processing (2)
  • src/main/agent-hooks/server/server-row-ownership.test.ts
  • src/main/agent-hooks/server/server-row-ownership.ts

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.

@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

  • Structural row comparison — commitStatusRowMutation now compares rows with the existing structuralValuesEqualIgnoringUndefined helper instead of JSON.stringifying both toAgentStatusIpcPayload results; same-reference and both-absent rows short-circuit before any walk.
  • New change-detection test — server-row-ownership.test.ts pins unchanged cases (same reference, bookkeeping-only rebuild, key reorder) and changed cases for each published field, plus row appear/disappear.

The comparison field set is unchanged: the five stripped fields (receivedAt, evidenceObservedAt, observation, launchToken, promptInteractionKey) match the old destructure. The only intended semantic difference is key-order insensitivity, and it is the safe direction — it can only suppress a spurious republish, never hide a content change. The reference short-circuit doesn't introduce a new miss either: when both sides alias the same nested object, the old JSON.stringify compare also read the same mutated content on both sides. I verified the key-order test is load-bearing (the ...entry.payload spread carries the producer's key order through toAgentStatusIpcPayload), and the new test passes locally.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready to merge

Verdict: no code changes needed. The PR removes the serialization cost it targets, and the set of changes that trigger a republish to paired clients is unchanged (the only difference: key order alone no longer counts as a change).

Review loop: an independent review came back clean on the first pass. It covered all 19 call sites, every field type in the published status (only plain JSON-shaped data, so the structural compare never falls back to reference equality in practice), and a revert experiment (only the key-order test fails without the fix, as intended). Keeping the published projection as the single definition of what is compared was judged better than a hand-maintained field list, which would drift as the payload grows.

Readiness checklist: passed at the start and the end of the review, with nothing blocking. A standalone benchmark of the compare alone measured about 4-7x less time per call for 7-8 KB rows.

Live QA (dev build on a separate Mac, merge base vs this PR, fresh isolated profile per arm, a scripted Claude hook sequence run through the installed hook script inside a real terminal pane, with a paired-client session.tabs subscriber attached):

  • Desktop status rows are identical in both arms: working, tool name, subagent row, done with the reply preview. Screenshots are in the PR body.
  • The paired client gets a snapshot for every real change in both arms and ends on done with the full reply. Per-step frame counts match (one step coalesced differently, with the same content).
  • Phone emulator: not run (the isolated host only pairs on loopback).

Seen in both arms, not caused by this PR (possible follow-ups):

  • Re-sending an identical Stop hook still produces one session.tabs snapshot per event, differing only in freshness fields. The phone shows no visible change. I have not attributed which publish path emits these.
  • A subagent start/stop produces two paired-client frames whose content is unchanged, because the paired projection carries no subagent info for the pane.

CI: all green (36 passed, 13 skipped). The first run had one failing test shard, in src/main/browser/browser-session-ua-wire-identity-cross-context.electron.test.ts, an Electron browser test unrelated to this diff; it passed on re-run.

@brennanb2025
brennanb2025 merged commit 9b11b1d into main Sep 28, 2026
82 of 84 checks passed
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