feat(agent-harness): share client state and cursor recovery - #5643
feat(agent-harness): share client state and cursor recovery#5643iscekic wants to merge 1 commit into
Conversation
| if (needsSnapshot) continue; | ||
| failures = 0; | ||
| delay = interval; | ||
| publish({ ...state, connection: { status: 'connected' } }); |
There was a problem hiding this comment.
WARNING: Successful polls always publish a new state object
publish({ ...state, connection: { status: 'connected' } }) allocates a new HarnessState even when connection.status is already 'connected'. publish only skips on reference equality, so every empty poll notifies subscribers. useHarnessState reads this store through useSyncExternalStore, so React will re-render on each poll interval (default 1s) with no data change.
| publish({ ...state, connection: { status: 'connected' } }); | |
| if (state.connection.status !== 'connected') publish({ ...state, connection: { status: 'connected' } }); |
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (4 files)
Fix these issues in Kilo Cloud Reviewed by grok-4.6 · Input: 285.1K · Output: 34.6K · Cached: 211.6K Review guidance: REVIEW.md from base branch |
No new behavior — the product does not use these additions.
Summary
Kilo-Org/cloud; worktree:/Users/igor/Projects/.worktrees/shared-agent-harness-3bb0.shared-agent-harness-3bb0-s4; base:origin/shared-agent-harness-3bb0-s3.HarnessState,HarnessAction, andHistoryPagegiveharnessReducersnapshot replacement, ordered event reduction, and history merging that preserves live messages and pending work.ConnectionStateandSyncFailureseparate connection failures from run outcomes;SynchronizationErrorrejects invalid conversation data, stale snapshots, and event gaps.Replayed events cannot restore resolved work or partial text, and missing snapshot records disappear without fabricated completion.
Files
packages/agent-harness/src/state.ts— Source; A (added), 136 lines (+136/-0). Adds idle initialization, indexed records, and message ordering by creation time, then identifier. Tracks active runs and stable queue order, retains interaction resolutions, and adds or removes pending actions by tool-call identifier. Validates conversation and action identifiers, ignores replayed sequences, and raises retryable errors for stale snapshots or event gaps. History changes only messages and the history cursor; connection changes do not complete runs.createHarnessStoreaddsHarnessStore, validatingEventPageSchemaandHistoryPageSchemabefore applying data and replacing snapshots after cursor expiry or event gaps.ResumeOptionsrequires conversation and client identifiers,HarnessTransport, andHarnessClock; optionaljournalandbridgehints useChangeSourceto trigger reads, never effects.Callers own
refresh,loadHistoryerror handling, anddispose;pollIntervalMsdefaults to 1,000 milliseconds, and nonretryable failures require a new store.Files
packages/agent-harness/src/resume.ts— Source; A (added), 200 lines (+200/-0). Adds snapshot-first reads, 200-event pages, and 50-message history requests; both page schemas accept at most 200 records. Validates protocol versions and conversation identity, publishes event batches atomically, coalesces refreshes, and allows one immediate snapshot replacement per pass. Retryable failures retain run state and use exponential backoff capped at 30 seconds; unknown failures become retryableconnection_losterrors. Drops history responses after snapshot replacement, cursor changes, blocking, or disposal; rejected history loads preserve state. Keeps subscriptions receiver-independent; disposal cancels polls and change subscriptions, notifies listeners once, and ignores late reads.useHarnessStateexposesHarnessStoreto React throughuseSyncExternalStore, with the same snapshot getter for client and server rendering.The hook observes state only, so callers still own refresh and disposal; this branch does not connect any product host.
Files
packages/agent-harness/src/react.ts— Source; A (added), 8 lines (+8/-0). Adds a client hook that forwards the subscription and shared snapshot getter to React without starting synchronization.Tests: 1 test file added:
packages/agent-harness/src/resume.test.ts(Test; A; 566 lines, +566/-0). Covers bootstrap, replay, cursor recovery, history races, message preservation, pending work, run queues, retries, blocking, notifications, and disposal.Generated: 0 files changed.
Verification
Manual verification: skipped. This level adds shared state and recovery modules without deployed consumers.
Visual Changes
Visual Changes: N/A
Reviewer Notes
Human steps
None before merge or after merge.
Notes
E2E: This level adds shared state and recovery modules without deployed consumers. Full runtime verification runs on the completed stack tip.
Stacked PRs — merge bottom to top. Each level shows only its own diff.
Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.
shared-agent-harness-3bb0— chore(agent-harness): register workspaces and enforce CI boundaries #5632shared-agent-harness-3bb0-s2— feat(agent-harness): define portable domain and snapshots #5637shared-agent-harness-3bb0-s3— feat(agent-harness): define commands tools and permission policy #5639shared-agent-harness-3bb0-s4— feat(agent-harness): share client state and cursor recovery #5643 ← this PRshared-agent-harness-3bb0-s5— feat(agent-harness): persist command intents and execution receipts #5647shared-agent-harness-3bb0-s6— feat(db): add harness ingress grants and retirement fences #5655shared-agent-harness-3bb0-s7— feat(agent-harness): deliver legacy history and project durable text #5659shared-agent-harness-3bb0-s8— feat(agent-harness): authorize durable grants and registered clients #5662shared-agent-harness-3bb0-s9— feat(agent-harness): fence retirement and retry payload cleanup #5667 (tip)