Repository navigation
fix(claude): correlate prompt turns with native command lifecycle - #313
Merged
Merged
Conversation
This was referenced Oct 10, 2026
observe: phaseLabel says "Running <tool>" while claude still writes the call's arguments (0.52)
#314
Closed
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
…arness (#315) Windows CI keeps failing with `EBUSY: resource busy or locked, rmdir …` when a vendor test removes a directory that a runtime process was using a moment before. #296 (#288) fixed `credential-redaction.vendor.test.ts`. #313's CI then hit the same error in `claude-resume.vendor.test.ts` ("Claude missing resume fails during initialize…", run 38032859591). Rather than fixing these one by one: every remaining `rm` of such a directory in sea-trial's vendor tests, harness (`aimock.ts`, `aimock-acp.ts`, `support/claude-fifo.ts`) and cases now uses `maxRetries: 10, retryDelay: 300`, as the already-fixed ones do. The recording helpers (`sea-trial/record/*`) don't run in CI and are left alone. Test-only; no release. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan
force-pushed
the
fix/claude-command-lifecycle
branch
from
October 10, 2026 07:26
714fa01 to
6c5c19f
Compare
Merged
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Release OAR and CLI 0.53.0. This PR changes only the two package version fields. **Fixed: a host prompt gets its own answer on claude** (#308, #313) - A host prompt sent while claude is busy (for example as a background task finishes) can wait behind a turn claude starts on its own. OAR used to end the prompt at that other turn's result and hand the host the wrong text. claude now reports each prompt's own `command_lifecycle` (`queued`, then `started`), and OAR attributes the turn by it: - `input_queued { inputId }` (new) means claude holds the input and has not started its turn; - `turn_active` gains an optional `inputId` for the input whose turn claude started; - a turn without that id while the prompt waits is a separate turn. `promptAndWait`, `awaitTurnEnd(…, inputId)`, `awaitIdle`, `statusOf` and the session view all follow this, live and on replay. An ordinary prompt shows no change: no idle flicker and no moved bubble. - `promptAndWait` now sends a fresh UUID `inputId` when the caller gives none. `awaitTurnEnd` takes an optional `inputId`. - **`abort()` while a host prompt is still queued** sends claude's interrupt with `cancel_queued` (when claude declares `interrupt_cancel_queued_v1`). The queued prompt is cancelled with the running turn, and `input_dropped { reason: "turn_interrupted" }` hands it back. Cost: claude also drops queued task notifications that have no id. - **A reused `inputId`:** claude ignores a user message whose id it has already seen. OAR used to wait until the abort fallback killed the process. Now `input_dropped { reason: "runtime_refused", failure: "invalid_request", message }` is emitted at once and the session takes the next prompt. Resend a dropped input with a **new** `inputId` on claude. **Added: claude workflow runs are tasks** (#305, #307) - Claude Code's local workflows (`local_workflow`) are reported as `TaskType` `"workflow"`, and agent teammates (`in_process_teammate`) as `"agent"`. A changed `task_progress.description` becomes `task_updated`. The phase and agent list (`workflow_progress`) stays in the native frame only, because it is outside claude's SDK schema. A workflow's spend appears in a later `result.modelUsage`. - A turn claude starts on its own (after a workflow, a queued message, a late steer) now emits `turn_active` at once, so the host does not show idle until text arrives. **Fixed: claude sessions no longer inherit a parent Claude Code session's markers** (#303, #307, #309, #310) - A host started from inside Claude Code passed that session's markers to every claude OAR started. The worst cases: `CLAUDE_CODE_CHILD_SESSION`, which made claude treat itself as part of the parent session; an inherited `CLAUDE_CODE_ENTRYPOINT`, which made an API-key session fail with "Not logged in"; and the parent's `CLAUDE_CODE_MESSAGING_TOKEN`. Sessions and the claude subcommands OAR runs (auth, login, logout, usage, model list, inventory, `claude update`) now drop the twelve markers claude itself drops when it launches an independent claude. An explicit `SessionOptions.env` value still wins, except `CLAUDECODE`. - A `compaction_ended` received while idle leaves status idle. **Added: install steps when OAR won't run them** (#311) - `requires_privileges` and `missing_tool` answers now carry the vendor's `steps` and `source`, for a person to run once they have the rights or the tool. OAR runs none of them. **Behavior changes** - New event kinds `input_queued`, plus optional fields on `turn_active` (`inputId`) and `input_dropped` (`failure`, `message`, only with `runtime_refused`). Hosts with an exhaustive `switch` need the new case. - `TaskType` gains `"workflow"`. - `promptAndWait` always sends an `inputId`, so the input's identity in `ConversationInput` is that id, not the request id. - On claude, resend a dropped input with a new `inputId`. Validation: every PR passed all 17 checks on its final head. #307 differed from its CI tree only in the version fields from the 0.52.0 release. #311 was verified locally on top of #310 (typecheck, lint, full tests), and its merged tree equals that verified tree. #310 and #313 merged with trees equal to their CI trees. Lookout verified each against the real claude CLI with a mock provider, with no account: three workflow recordings, the environment of every claude process, and more than a dozen lifecycle recordings for #313 (collision, steer, queue, cancel before and after start, plain interrupt, fold-in, duplicate after drop and after resume). After this PR passes CI and merges, tag its exact squash commit as `v0.53.0` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Replaying a session's records lost the native parent/child graph, so
hosts such as Ferry could not reproduce `Session.usage().withChildren`.
Lineage now travels on the native frame that establishes it, and live
queries and replay use the same graph and token folds.
- Add `session_linked { parent, child, via: "tool_call" }` for Codex
collaboration items, ACP lineage notifications and OpenCode v2 child
attribution. `graphOf(records)` is exported through the observe, root
and browser entries. The kernel updates the same graph fold as each
record is appended, using a Set for node ids; `graph()` returns the
retained value without rescanning the log. Repeated facts retain their
original frames but produce one edge.
- Derive lineage by default in `usageOf(records, sessionId)`, retaining
its explicit graph override. SessionView keeps every session's latest
totals, so reports before lineage, nested descendants and repeated
cumulative figures contribute exactly once. Unrelated session ids never
imply a child, and the usage cursor includes the frame that establishes
relevant lineage even when another session reports it.
- Keep unknown accounting unknown. Old records without lineage do not
gain `withChildren`. Grok's root ledger already includes child spend:
its child ledgers remain native-only and are not added again. Correct
the contrary SessionUsage comment and attribution spec, linked to the
existing Grok evidence and regression.
Host impact: exhaustive event switches need a `session_linked` case.
Incremental SessionView checkpoints must retain `sessionGraph` and
`usageBySession` with its nested Maps; replay raw records when upgrading
checkpoints. The existing root `usageByAgent` and `usageTotal` fields
remain available. Adapter authors put the event returned by
`kernel.link(edge)` in the source frame; out-of-band `kernel.node()` is
removed. The live graph still starts with the known root id.
`graphOf([])` stays empty and learns the root from its first recorded
appearance; this initial seed is the only information supplied outside
the records.
Validation: full check (1,590 tests) and build on main aa8f5e3,
including #313, #315 and #317; all five behavior backends; 35 Codex
native tests. Added regressions cover JSON persistence, live/replay
equality after each append, synchronous source-frame observation,
incremental and flat-event views, graph and checkpoint immutability,
late edges, repeated reports, nested/shared descendants, cycles, unknown
totals and explicit graph overrides. Codex's actual Session path,
recorded Grok wire shapes and the OpenCode v2 child fixture all verify
replay against live results. All runtime tests use scripted providers,
with no real-account quota.
Closes #312.
---------
Co-authored-by: Otter <[email protected]>
8 of 14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A host prompt sent while a Claude workflow notification is starting can be accepted before the notification's result.
promptAndWaitthen returned the notification as the prompt's answer. Native input queue/start facts now associate the host's wait and message placement with its own turn.input_queued { inputId }and optionalturn_active.inputId. Queue evidence arms attribution without moving the input or changing visible status. A conflicting native turn gets its own segment; after it ends, the accepted prompt remains running/waiting_model until its own start and result. Records without queue evidence retain the existing fallback. Steer lifecycle frames remain native-only.awaitIdleand input-scoped wait helpers consistent live and in replay. This includes checkpointed status, prefix cursors, child scope, process exit and resumed input echoes.promptAndWaitsupplies a UUID; lower-level waits can use the id already generated on asession.prompt()request.interrupt_cancel_queued_v1, aborting a written but not-yet-started prompt sendscancel_queued: true, including beforequeuedarrives. Nativecancelledbeforestartedreturns that input viainput_droppedand resolves its wait as aborted without inventing a turn end. Afterstarted, cancellation remains native-only: the turn's result owns completion. Ordinary aborts and undeclared-capability behavior remain unchanged. The bulk option also drops queued task notifications without UUIDs; this cost is documented.input_droppedwithreason: "runtime_refused",failure: "invalid_request"and the explanation; release the owned slot and input-scoped wait without fabricating a turn or killing the process. A replay after queued/started remains normal delivery, including a prompt folded into a notification at a tool boundary.Host impact: exhaustive runtime-event switches need
input_queued; turn consumers can useturn_active.inputId. Save pending-input metadata with status checkpoints. Existing lower-level waits without an input id still return the first root end; an input-scoped wait also resolves on a native before-start input drop (aborted for interruption, failed for refusal). Only aruntime_refuseddrop permits the new optionalfailureandmessagefields; their fallback is unknown. Claude callers must use a fresh inputId for every resend, including after cancellation or resume. SessionView handles placement without a queued/started flicker.Validation: full check and build; all five behavior backends; Claude's 40 native tests. Replay compares each native frame with the production projection; targeted regressions cover visible status/layout, notification collisions, pre-queued aborts, cancellation before the receipt with no result, ordinary aborts after start, duplicate IDs without a native turn, their legitimate replay counterexample, and awaitIdle while another turn still runs. Original failures are retained in local logs. Fixtures use scrubbed paths and no account credentials; these checks spend no real-account quota.
Closes #308.