Repository navigation
fix(agent-hooks): compare status rows structurally instead of serializing both - #23585
Conversation
…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
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Structural row comparison —
commitStatusRowMutationnow compares rows with the existingstructuralValuesEqualIgnoringUndefinedhelper instead ofJSON.stringifying bothtoAgentStatusIpcPayloadresults; same-reference and both-absent rows short-circuit before any walk. - New change-detection test —
server-row-ownership.test.tspins 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Review status: ready to mergeVerdict: 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
Seen in both arms, not caused by this PR (possible follow-ups):
CI: all green (36 passed, 13 skipped). The first run had one failing test shard, in |

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:
session.tabs, so fields like sub-agents, the model, the provider session and the terminal handle genuinely need to trigger a republish.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:
Done with the reply preview, before / after:
Testing
New
src/main/agent-hooks/server/server-row-ownership.test.tspins 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 oxlinton the changed files, andpnpm run check:code-quality:changed. Live QA (dev build on a separate Mac, before = merge basea174a086d76, 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 tosession.tabs.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
docs/reference/agent-skill-sharing-upstream-boundary.mdand 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)