Skip to content

[lifecycle-RSK] RSK-10: Route stream, ask, and turn-field writes through events #1804

Description

@edelauna

Tracking

Context

The stream and ask regions and the turn fields need their writes routed before #1805 flips their reads. didToolFailInCurrentTurn alone has 54 writes in src/core/tools, so this may exceed 1 SP.

Developer Notes

  • streamStarted where the stream starts (Task.ts:3269). streamEnded in the finally block (Task.ts:3756).
  • streamCleanupFinished in abortStream, where it sets didFinishAbortingStream (Task.ts:3225).
  • turnStarted at the per-request reset block (Task.ts:3228-3245).
  • askStarted in Task#ask where a blocking ask sets lastMessageTs (Task.ts:1529, 1550, 1568), after the abort check from [lifecycle-RSK] RSK-20: Check abort before an ask posts #1803. Carry that askTs. This is the ask identity that the Bug: Multiple execute_command tool calls in single request only ask permission for first command #998 fix needs (PR-6). Do not drive it for a partial ask, which throws at once (Task.ts:1499, 1507).
  • askSettled with the same askTs in a finally block, so every blocking exit drives it: the abort throw (Task.ts:1679), the superseded throw (Task.ts:1689), and the return (Task.ts:1714). A stale askTs is a no-op (race R-6).
  • completionAccepted on the accept path in AttemptCompletionTool.ts. Pass the askTs of the completion ask. Task#ask does not return askTs today, so add it to the result object that ask returns as an optional field. Existing callers (about 40 call sites in 22 files, the 3 result types in AutoApprovalHandler.ts, and the test mocks) need no change, because they ignore the new field. Drive completionAccepted right after ask returns, before any other await. That ask has already settled, so the guard reads lastCompletionAskTs, not the ask region.
  • Route the turn-field writes: isWaitingForFirstChunk (4), didRejectTool (10), didAlreadyUseTool (2), didToolFailInCurrentTurn (54), and didCompleteReadingStream (2).
  • resumeAfterDelegation resets (Task.ts:2884-2886): delete them. The new instance already has the defaults.
  • If the change exceeds 1 SP, split per region and keep this issue as the tracker.
  • Confirm the comparison shows zero untagged divergence and zero untagged rejections on nightly.

Exit criteria: every stream, ask, and turn-field write goes through a helper. The fields stay authoritative. Tests pass.

Reversibility: reads are unchanged, so behavior is unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions