Skip to content

fix(bots): a turn a person stopped reads as stopped in its thread and chat, not an error - #51690

Merged
AmethystLiang merged 11 commits into
mainfrom
AmethystLiang/fix-stopped-bot-error
Nov 29, 2026
Merged

AmethystLiang merged 11 commits into
mainfrom
AmethystLiang/fix-stopped-bot-error

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What a user sees

Before: stopping a bot mid-turn could make its Slack thread say "Codex ran into an error, so stopped." and offer a Resume button, as if something had broken. The chat could also show an error row under the stopped turn.

After: the thread shows the normal "Stopped on ." status, with no error line and no Resume. The turn reads as stopped in the chat, with no error row. Real errors still show exactly as before.

If Codex reported an error before you pressed Stop, that error stays in the chat even though the turn then shows as stopped, because it happened before the Stop.

Why it happened

When a person stops a turn, the agent can report that interrupted turn as failed (Codex's failed completion, or Claude's error result). Orca kept that failure, so the thread was told the agent errored.

What changes

  • A turn end that reports a failure within 30 s after a person's Stop of that same turn is saved as stopped (cancellation).
    • The 30 s is measured from when Orca received the agent's frame.
    • A failure before the Stop, more than 30 s after it, on another turn, or after Orca's own stops (host stop, evict, context clear) keeps its error.
  • Codex's error rows, and a /compact command's own failure row, are decided by the same rule, once, by the journal writer. A later repeat of the same error is written only where the earlier row is missing, so a real error shows exactly once.
  • Codex error frames now keep their receipt time, as turn boundaries already do.
  • A stopped end that is written again (a duplicate completion, or a restore with a lost or rounded clock) stays stopped.

Checked against how comparable products handle this.

Testing

New tests run the real Codex and Claude journal translators, with Codex frames entering through the real notification handler, into the real journal writer, against a Stop saved by that writer. They cover:

  • the window's edges (0, 30 000 and 30 001 ms);
  • receipt time versus processing time;
  • an error notice and a completion on both an immediate and a delayed writer;
  • /compact turns, including a failed completion Codex repeats;
  • Orca's own stops;
  • a refused write;
  • re-published and restored turn ends;
  • the in-memory writer and lifecycle batch sizing.

The stop cases fail on main on their assertions; all of them pass with this change, along with the related existing suites, typecheck, lint and format.

Performance

  • A failed turn end does one indexed single-row read of the saved Stop, inside the writer transaction it already runs in. Successful ends are untouched.
  • Each Codex terminal error row is decided once by the writer with that same read. A repeat adds one point read of the row it repeats.
  • There is no deferred state, no new subscription, no timer and no scan.
  • Codex error frames get one clock read each for their receipt time.
  • A failed /compact writes its failure row as its own resolved write.
  • A settled /compact keeps its provider turn's link to the command's turn in a map of at most 8 entries, so a repeated completion is decided against the command's Stop.
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​692 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​692
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​761 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​649

…t an error

A provider can report a turn it was interrupted out of as failed (Codex's
failed status, Claude's error result). The journal's Stop rule only decided
turn ends with no verdict, so that failure was kept and the Slack thread said
the agent ran into an error and offered Resume. A failure that ends within 30s
after a person's Stop for that same turn now reads as cancellation; a failure
before the Stop, long after it, for another turn, or after Orca's own stop
keeps its error.
…n the chat

Codex's terminal error rows (its error notice and a failed turn/completed) are
written as a stop-decided row with the failure window, so the writer drops the
row when a person's Stop of that turn came at most 30s before it. The turn-end
rule and these rows share one predicate, personStopDecidesFailure. Real errors,
errors long after the Stop or before it, Stops of other turns and Orca's own
stops keep the row.
… Stop row change

Imports AgentJournalTurnScope from its own module in the test, moves the Codex
frame row write and its terminal-turn check unchanged into codex-frame-row-write.ts
so the frame writer stays under the line limit, and wraps one call as oxfmt does.
No behavior change.
… by receipt time

- Claude's error-result and plugin-input stop checks carry failure, so the
  stop-decided write and the quota end use the bounded window (C1-1).
- A stopped end written again keeps its cancellation for a failure in the
  Stop's window, a lost clock or one rounded to the second (C1-2).
- Codex error rows are judged at the frame's receipt time, the time its turn's
  end uses (C1-3), against the command's own turn for a command turn (C1-5).
- A Codex completion repeating an error whose row a Stop dropped, or whose
  decision is still pending, is decided at its own receipt time (C1-4).
- The in-memory timeline view takes stopDecidesFailure like stopDecidesTurn (C1-7).
- Tests drive the real Claude and Codex translators into the real SQL writer,
  and cover the window's edges, Orca's own stops and the in-memory writer (C1-6).
…lock, inside the window

The one-second same-end tolerance kept a distinct failure just past the 30s
window, or just before the Stop, as stopped. It now applies only to a whole-second
completedAt the stopped end rounds to, at or after the Stop's second and inside the
window (C2-5). Tests write the window out instead of importing it, so on sources
without it they fail on their assertion rather than on a NaN clock, and the shared
writer fixture can refuse resolved writes like a backpressured queue.
…it carried on arrival

Removes the deferred repeat callback. A completion repeating the error of an
earlier row of its turn is written in its own batch as a Stop-decided row that
lands only where that earlier row is missing (the new literal-if-absent writer
resolution); its journal turn (a command's own), attribution, frame turn and
receipt time are fixed when it arrives (C2-1, C2-3, C2-6). Codex error frames get
their receipt stamped like turn boundaries (C2-2). A compaction's own failure row
is a Stop-decided row ahead of the batch that settles the command (C2-4).
… only where that row shows

After Codex's own error frame was admitted, the compaction's failure row was
suppressed, so a frame a Stop dropped left a late failed compaction with no
error row. The row is now written as a Stop-decided row that lands only where
Codex's terminal row for the turn is missing, checked by the writer
(literal-if-absent names the row it checks). No callback or deferred state.
…action it ended

The error row is written under the active turn when the frame omits turnId, but
errorShown read only an explicit turnId, so a compaction that then ended without
a marker showed both rows. errorShown now falls back to the active turn the same way.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Journal turn-end processing now allows a matching person-initiated Stop to decide a provider failure within 30 seconds. Claude and Codex translation paths pass failure and timing data into journal writes. Codex failure rows use stable identities, optional duplicate guards, and writer admission handling. Tests cover time boundaries, Stop ownership, repeated writes, deferred processing, and writer refusals.

Merge Risk: Low · up to 8f64a

A turn a person stopped now reads as stopped rather than as an error. Two minor edge cases remain open: failures received right at the 30-second boundary when no timestamp is supplied, and repeated failed completions for old stopped /compact commands. Both are bounded and can be followed up.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is mostly complete and well organized. It explains the user-visible before and after, the mechanism (Codex failed completions and Claude error results after a person's Stop), the speci… Add an ELI5 section in plain language. Link a real issue under Linked Issue (replace the empty "Fixes #"). Add a Visual Proof section with before and after screenshots or a video of the Slack thread and chat, because the change alters user-…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: a turn that a person stopped is recorded as stopped (cancellation) in the thread and chat instead of as an error. The changeset adds a 30-second Stop window that decid…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a turn that a person stopped is recorded as stopped (cancellation) in the thread and chat instead of as an error. The changeset adds a 30-second Stop window that decides failures for Codex and Claude turns, which matches the title. The title is long (88 characters) and uses the 'fix(bots)' prefix, but it is specific and related to the change.

Full details: Description check

Explanation

The description is mostly complete and well organized. It explains the user-visible before and after, the mechanism (Codex failed completions and Claude error results after a person's Stop), the specific rules (30 s window measured from receipt, exclusions for pre-Stop, later-than-window, other-turn, and Orca-initiated stops), and a detailed testing section. It also has a Performance section with concrete reasoning. Several template sections are missing or incomplete: the ELI5 section is absent, the Visual Proof section is missing (the change alters visible chat and thread behavior, so a before/after or an explicit N/A with reason is required), the Linked Issue section is empty ("Fixes #" with no number), the manual-testing and test-anti-pattern checklist items are not indicated, the Risk section has no Level and no revert or back-out guidance, the Review and Agent skill upstream boundary sections are not addressed, and the Checklist is not ticked. The Testing section does not state which platforms were tested (macOS, Linux, Windows, SSH). The Performance section is substantive.

Resolution

Add an ELI5 section in plain language. Link a real issue under Linked Issue (replace the empty "Fixes #"). Add a Visual Proof section with before and after screenshots or a video of the Slack thread and chat, because the change alters user-visible behavior. Or write N/A with a reason only if no visual change applies. In Testing, state the platforms tested (macOS, Linux, Windows, or SSH) and tick the applicable checklist items, including manual testing and the test anti-pattern check. In Risk, set the Level (Low, Medium, or High), name the riskiest part, and state how to back it out, including what a revert would not undo, for example saved journal rows already written. Complete the Agent skill upstream boundary checkbox. Add the AI Disclosure if an AI model was used, and complete the Checklist.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7195b758-916c-4101-ac8c-36327055647f
Commits

Reviewing files that changed from the base of the PR and between 83042dd and 8f64a85.

Files selected for processing: 3

  • src/main/codex/structured/journal/codex-journal-command-turn.ts
  • src/main/codex/structured/journal/codex-turn-failure-stop.test-fixture.ts
  • src/main/codex/structured/journal/codex-turn-failure-stop.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Minor comments: 1

src/main/codex/structured/journal/codex-structured-journal-generic-frames.ts: 1

112-112: Minor · Functional Correctness · Low value

Capture the fallback receipt time when the frame arrives.

When a notification omits observedAt, receive stores undefined. receiptTime() then reads the clock when the failure row is written. The row time therefore includes any processing that runs between the frame entering handle and the write. The skew is small, so only failures received within that skew of the 30-second Stop boundary can be classified differently. Capture the fallback at entry instead. Explicit observedAt values are preserved.

Suggested fix

   receive(observedAt: number | undefined): void {
-    this.receivedAt = observedAt
+    this.receivedAt = observedAt ?? this.deps.now?.() ?? Date.now()
   }
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5bfec735-2d64-4b8b-9583-6cf949db051b
Commits

Reviewing files that changed from the base of the PR and between 375d675 and d2bfc59.

Files selected for processing: 23

  • src/main/claude/claude-stop-readings.ts
  • src/main/claude/structured/journal/claude-plugin-input-failure-journal.ts
  • src/main/claude/structured/journal/claude-result-journaling.ts
  • src/main/claude/structured/journal/claude-result-stop.test.ts
  • src/main/codex/structured/journal/codex-frame-row-write.ts
  • src/main/codex/structured/journal/codex-journal-command-turn.ts
  • src/main/codex/structured/journal/codex-structured-journal-generic-frames.ts
  • src/main/codex/structured/journal/codex-structured-journal-translation-turn-boundaries.ts
  • src/main/codex/structured/journal/codex-structured-journal-translation-writers.ts
  • src/main/codex/structured/journal/codex-structured-journal-translation.ts
  • src/main/codex/structured/journal/codex-turn-failure-stop.test.ts
  • src/main/codex/structured/journal/codex-turn-failures.ts
  • src/main/codex/structured/session-lifecycle/codex-structured-session-state.ts
  • src/main/native-chat/agent-session-journal/context-epochs/journal-stop-turn-end-writes.test.ts
  • src/main/native-chat/agent-session-journal/context-epochs/journal-stop-turn-end.test.ts
  • src/main/native-chat/agent-session-journal/context-epochs/journal-stop-turn-end.ts
  • src/main/native-chat/agent-session-journal/journal-domain-item-normalization.ts
  • src/main/native-chat/agent-session-journal/journal-domain-timeline-reads.ts
  • src/main/native-chat/agent-session-journal/journal-stop-writer.test-fixture.ts
  • src/main/native-chat/agent-session-journal/writing/journal-lifecycle-batch-partition.ts
  • src/main/native-chat/agent-session-journal/writing/journal-timeline-resolution.ts
  • src/main/native-chat/agent-session-journal/writing/journal-timeline-view.ts
  • src/main/native-chat/agent-session-timeline/agent-journal-turn-failure-revision.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the repeated-completion issue is addressed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the repeated-completion issue is addressed.

Summary

The PR makes failures reported shortly after a person’s Stop read as stopped, while keeping errors outside that rule.

  • A recent Stop makes that turn’s provider failure read as stopped.
  • Codex reports a stopped failure without adding an error row.

Reviews (2) · Last reviewed commit: "fix(bots): a repeated failed completion ..." · Reviewed by Greptile

…he command's Stop

After a command settles, its provider turn keeps a link to the command's
journal turn (the last 8 settled commands), so Codex repeating the failed
completion is decided against the command's Stop instead of showing an
error row.
@AmethystLiang
AmethystLiang merged commit babbfc5 into main Nov 29, 2026
60 checks passed
@AmethystLiang
AmethystLiang deleted the AmethystLiang/fix-stopped-bot-error branch November 29, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant