Repository navigation
A Stop just after the agent asked records how Pine ended the turn: endings follow Pine's order (A10, P0) - #255
Merged
Conversation
…dings follow Pine's order, and a Stop after the recorded end is a no-op Monkey test A10 (2026-11-15, turn _173): Pine ended the turn needs_input at 10:13:51.420 (pine-dev gateway log). The person pressed Stop 0.93 s later, while the Studio still recorded the turn running (grace, event drain, collection). The Stop's cancel reached Pine at 10:13:53.294 and closed the question. The follower then recorded needs_input from the read it had taken before the cancel. The Chat said "1 waiting for you" for a question Pine no longer had. - A turn's ending is recorded by one compare-and-set on Pine's order: TurnView.lastEventId, the turn's place in its Task's ordered log. A cancel that closes a question moves it there (PineSandbox turns.go closesFoldedQuestion, broker.go cancelQuestion). Store.recordEnding writes only when no later ending of the current turn is recorded, so an earlier read never replaces a later ending. Schema step 21 adds chats.ending_event_id (store.ts MIGRATIONS). - The Stop only sends the cancel. PinePort.cancel returns the turn Pine answers with (SDK agent.cancel returns an AgentTurn). Its pass records that ending in the Chat's line, then follows as before. - Every ending goes through recordTurnEnding, in the Chat's line: the compare-and-set, then the idle timeout for the state just recorded. Two of a Chat's idle-timeout changes never overlap. - cancelTurn cancels only a turn the Chat records as running. A Stop after the recorded end does nothing on Pine, as codex-rs app-server refuses "no active turn to interrupt" and Code-OSS cancels nothing once a request is complete. Left as it was: - A cancel whose answer is lost records nothing from the Stop (the lost-response family of #193). - The stopped response still cannot show a question recorded before the Stop (Code-OSS drops progress after a cancel). - Code-OSS keeps queued messages after a Stop and drops them on Reload (#253). Signed-off-by: SitgesRun <169425442+SitgesRun@users.noreply.github.com>
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.
Monkey test 2026-11-15, finding A10 (P0): Stop pressed just after the agent asked hides the question, and the Chat waits for nothing.
Root cause (pine-dev gateway log + Studio log; the two clocks agree within 15 ms)
GET agent/turns/turn_…_173returns after 9375 ms: Pine ended the turnneeds_inputrunning(grace, event drain, collection), socancelTurnsends a cancelPOST agent/cancel202: Pine'sCancelTurncloses the waiting question (broker.gocancelQuestion)needs_inputfrom the read it took before the cancelTwo writers recorded one turn's ending, and the stale one won. The status line said "1 waiting for you" for a question Pine no longer had.
Fix: endings follow Pine's order (compare-and-set); Stop only sends the cancel
Endings are ordered by Pine.
TurnView.lastEventIdis the turn's place in its Task's ordered log (SDKAgentTurn.lastEventId). A cancel that closes a question moves it there (PineSandboxturns.goclosesFoldedQuestion).Store.recordEndingwrites in one statement, only when no later ending of the current turn is recorded (the shape of HTTP If-Match or a Kubernetes resourceVersion).chats.ending_event_id, appended toMIGRATIONS.Stop only sends the cancel (codex-rs: the turn's own path records
TurnAborted).PinePort.cancelreturns Pine's answer, anAgentTurnfrom the SDK.One writer path.
recordTurnEndingruns the compare-and-set, then the idle timeout for the state just recorded. Every writer goes through it in the Chat's line, so a Chat's idle-timeout changes never overlap.A Stop after the recorded end is a no-op, as codex-rs app-server refuses "no active turn to interrupt" and Code-OSS's cancel of a completed request does nothing.
cancelTurncancels only a Chat recordedrunning.Unchanged
doc/protocol.md4.4, "Stop", says the new rule.Tests
Failing-first, on the old code with only the tests (
4f9fd97c), on pine-dev:npm test: tests 339, pass 335, fail 3.The 3 tests that failed there, at this head:
canceled; the Chatidlewith no question waiting;ending_event_idis Pine's; the question row is kept, then "You stopped this turn".New tests that did not run on the old code:
4. The same ending read twice is recorded once and said by both readers.
5. Store unit tests: equal or smaller ids are refused, a larger id is accepted, and only for the current turn; a schema-20 store upgrades with the column null.
Existing fixtures corrected:
chats.test.ts(2 places) andrestartFollower.test.tsforge a running Chat over a turn whose ending was already recorded. They now also clearending_event_id, so the state they simulate is whole: nothing of the turn recorded yet. Without that, the compare-and-set correctly refused their re-read of the same ending.projectEntry.test.tsand the migration probe inprotocolFlow.test.tsno longer hard-code schema 20/21.Gate, pine-dev on this exact head
6497b7e8a9f075869c1db4c872543fca6551f28a:npm test: tests 342, pass 341, fail 0, skipped 1; render smoke 30 of 30; release safety tests passed.npx tsc -p .is clean.Codex (read-only):
Left as is (stated)
needs_inputcan stand in the status line until the next message (which is a new run anyway). Same lost-response family as A Stop during a run whose response was lost leaves the turn running, and it may spend money #193.CancelTurngap (202 while a question stays open, if the run's result lands between its read andmarkCanceling) is a local note for Pine's owner. It is not this run's path.