Skip to content

feat(native-chat): show a Codex chat's goal above the composer, and set it from goal mode - #22377

Merged
brennanb2025 merged 5 commits into
mainfrom
brennan/sta-8159-codex-chat-ui-omits-persisted-thread_goal_updated-when
Sep 23, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennan/sta-8159-codex-chat-ui-omits-persisted-thread_goal_updated-when

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1577 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1568
Prod 43 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1266 $\color{#cf222e}{\Huge{\mathbf{−}}}$​90 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1176

ELI5

When you give Codex a goal in a structured chat, Orca now shows that goal in a small bar above the message box, with buttons to pause, resume or clear it. It stays there when you close and reopen the chat, which it didn't before. You can also type /goal to switch the message box into "goal mode", so what you send becomes the goal instead of a normal message.

What Changed

Before: Codex goal changes showed up as grey "Codex · Goal set: …" lines in the chat. When you reopened a Codex session from history, the goal wasn't shown anywhere, so you couldn't tell a goal was active. /goal <text> was sent to Codex as ordinary message text, and it was up to the model to create the goal.

After (structured Codex chat, desktop):

  • Goal bar above the composer: "Pursuing goal …" or "Paused goal …", followed by the time spent. It has buttons to clear, pause/resume and expand the full objective. A goal Codex reports as blocked or stopped by a usage limit shows "Goal blocked" or "Goal limited" and can be resumed the same way a paused one can; a goal whose token budget is spent can only be cleared. It's hidden when there is no goal or the goal is complete.
  • Goal mode: picking /goal, or typing /goal on its own and pressing Enter, switches the composer into goal mode. A Goal chip appears (hover shows ✕; its label is "Exit goal mode", so it is never confused with the bar's "Clear goal") and the placeholder becomes "Describe your goal, define measurable outcomes for best results". Sending sets the goal through Codex's goal API (thread/goal/set). Codex then starts working on it by itself; no chat message is sent. /goal <text> still sets that text as the goal directly, inside goal mode or out of it. If you keep typing while a goal is being set, that text stays in the box once the goal lands.
  • "Sent as goal": the objective you sent appears as your message, with a "Sent as goal" line under it.
  • No grey rows: the goal status lines no longer appear in the desktop chat. They are still saved, because the goal bar reads from them.

Mechanism:

  • Goal state: the goal is treated as the chat's current state, not as part of the conversation. Orca already saves each goal notification Codex sends as a row in the session's history. Those rows now also carry the goal itself as typed data (objective, status, time and tokens used, budget, timestamps). The goal bar shows the latest one.
  • Reopening: Codex sends the current goal again every time a chat is reopened (resumed). So a reopened chat, or a Codex session opened from history into a new chat, gets its goal back without Orca reading Codex's session file.
  • Old goal rows: when a goal update changes only the time or token counts, Orca updates the existing goal row in place instead of adding a new one. Because that updated row keeps its original position, a chat that only has the newest part of a long history loaded ignores the live update when the row is older than what it has loaded; otherwise the update would become the "load earlier" starting point and scrolling back would skip everything between. The saved history keeps the update, and it arrives when the user scrolls back to that row.
  • Controls: pause, resume, clear and set go through a new session action, agentSession.threadGoal. It uses the same admission, deduplication and history path as the other chat session actions.
  • Replacing a goal: Codex's thread/goal/set on a thread that already has a goal rewrites that goal's objective and keeps its id, timer and token count. So when the chat already records a goal (any status, including complete), Orca sends thread/goal/clear first and then thread/goal/set, and the new goal starts from zero.
  • Lost responses: if a goal change's reply never arrives (for example a request timeout on a remote host), the next attempt is answered from the goal state the chat already records, or run again. Without this, one timeout would leave Clear, Pause and Resume refused as "unknown" until the chat was reopened.
  • "Sent as goal" marker: the objective is saved as a user message tagged sentAs: 'goal', before Codex is asked to set the goal. That puts it ahead of the work Codex starts, and keeps the label after a reload. If Codex refuses the goal, or the request fails, the message is removed.

Why

The goal describes the chat as a whole, and Codex is the one that keeps track of it. Showing Codex's latest goal report as persistent state fixes the reopen bug at its cause. The alternative was to rebuild goal history from Codex's session files. That keeps a second copy of the goal that can disagree with Codex; it can still say "paused" after the goal was cleared, which we saw during testing.

Where this intentionally differs from reading the goal live from Codex:

  • Reopening: the bar comes from the saved goal row, which Codex refreshes on resume. Orca does not ask Codex for the goal each time a chat opens.
  • Update rate: while a turn runs, updates that change only the counters rewrite the row at most about every 30 seconds. Codex reports every ~2s, and the saved history never drops old versions. The timer keeps counting up on its own while a turn runs, so the bar stays accurate. While idle, it can lag Codex's total by up to 30s until the next resume.
  • Older hosts: if a host doesn't support the new session action, it returns no goal info. The goal controls then stay hidden, and /goal falls back to being sent as text.

Linked Issue

Fixes STA-8159 (https://linear.app/stably/issue/STA-8159/codex-chat-ui-omits-persisted-thread-goal-updated-when-reopening-a)

Visual Proof

Before: reopening a goal session showed no goal anywhere; the Linear ticket has the transcript evidence.

After, from a real Electron dev build (fresh profile) with the real Codex CLI:

Goal mode, hovering the chip to clear it:
A2-chip-hover-clear.png

Goal set: "Sent as goal" label and the "Pursuing goal" bar:
B1-goal-active.png

Paused:
C2-goal-paused.png

After quitting and relaunching the app (dark and light themes):
D4-after-restart-paused-dark.png
D3-after-restart-paused-light.png

The exact bug case: a Codex session with a paused goal, opened from Agent Session History into a new chat on a fresh profile:
F1-adopted-chat-banner.png

Testing

  • I manually tested these changes locally (macOS, Electron dev build, real Codex CLI):

    • goal mode: enter it, leave it with the chip, send;
    • "Sent as goal" and the pursuing bar, including the ticking timer and the bar disappearing when the goal completes;
    • pause, resume, clear;
    • quit and relaunch with a paused goal, where the time stayed correct;
    • a cleared goal stays gone after relaunch;
    • opening a session from history into a new chat on a fresh profile. The goal row was written by Codex's resume, two seconds after the chat opened. Opening a session whose goal had been cleared showed no bar, even though Codex's session file still said "paused";
    • normal messages still send normally.

    Codex's own records confirmed each goal change.

  • Automated tests added/updated:

    • deriving the current goal;
    • the Codex request each goal change sends;
    • the message tagged "sent as a goal", including removing it when Codex refuses or the request fails;
    • clearing before setting when a goal is already recorded, in request order, and stopping if the clear is refused;
    • answering a lost goal-change response from the recorded goal, and running again otherwise;
    • a counter-only goal update reaching a subscriber's live page under the row's original position;
    • a typed bare /goal entering goal mode;
    • resume on a blocked or usage-limited goal, and only clear on a spent budget;
    • /goal <text> inside goal mode naming <text>, and a draft edited while the goal was in flight staying put;
    • a lost status-change reply read as applied only when the recorded goal is in that status, and a cleared row in the loaded window outranking the host's earlier answer;
    • validation of the new saved fields;
    • updating the goal row in place, with its position unchanged, under the throttle, and on resume;
    • a live update of a row older than the loaded window leaving the "load earlier" starting point where it was, and landing when that part of the history is loaded;
    • a goal set that arrives while a provider goal report is still waiting to be saved still counting as a replacement;
    • the goal bar, goal-mode chip and hidden goal rows;
    • the RPC method count and cross-version wire test.

    pnpm tc:node and pnpm tc:web pass. Vitest (config/vitest.config.ts) on native-chat, codex, agent-session-wire, rpc methods and shared: 1456 files / 15517 tests pass. The changed-code quality gate and oxlint pass.

Not tested visually: expanding a goal too long for one line, and mobile.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Remote/SSH and mixed versions: the new session action and both saved fields are optional additions. Older hosts never send goal info, so the goal controls stay hidden. Older clients see the objective as a plain user message and ignore the typed goal data.
  • Mobile: unchanged. Mobile still shows its plain-text goal lines, and it will also show the objective as a user message. A goal bar for mobile is a follow-up.
  • Cross-platform: renderer and host logic only, with no platform-specific paths or shortcuts.
  • Known limitations:
    • Pausing doesn't stop a turn that's already running; that's Codex's behavior.
    • A Codex session whose only input was a goal shows as empty in history and can't be opened into a new chat. That's an existing history filter, left for a follow-up.
  • Follow-ups not in this PR: editing a goal, a "Replace current goal?" confirmation, a "Resume paused goal?" prompt, and the terminal-backed chat lane.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…t it from goal mode

Structured Codex chat now treats the thread goal as session state: a banner above the
composer shows the current goal (pursuing / paused) with clear, pause/resume and expand;
/goal enters a goal mode whose send calls thread/goal/set; the objective is journaled as a
user message marked as sent as a goal. The banner is derived from the journaled goal rows,
which Codex's resume snapshot refreshes, so a reopened or adopted chat shows its goal.

Fixes STA-8159
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change adds thread-goal support to structured sessions. It defines goal data and journal transitions, reads and tracks Codex goal frames, and exposes set, pause, resume, and clear operations through the host and RPC. Native Chat adds /goal composer mode, displays current goal status and elapsed time, and provides goal controls. Goal-setting messages are recorded with a send-mode marker, and goal transition frames are filtered from structured-session transcripts.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 7280c

Older chat history can show stale goal information, and retrying an uncertain goal request can repeat provider work. Resolve these goal and paging behaviors before merging; the smaller command and test gaps also remain.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 77 functions across 55 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main changes: showing a Codex goal above the composer and setting goals from goal mode. It is specific and related to the pull request.
Description check ✅ Passed The description covers the required sections with a clear user-facing explanation, rationale, linked issue, visual proof, and detailed testing information. The AI Disclosure and Review sections are bl…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: fa5e9d01-a894-46d4-b9d9-226190d6d089

📥 Commits

Reviewing files that changed from the base of the PR and between 9af6a3d and 56db245.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (57)
  • src/main/codex/codex-goal-journal-rows.ts
  • src/main/codex/codex-structured-journal-goal-resume.test.ts
  • src/main/codex/codex-structured-journal-goal-revision.test.ts
  • src/main/codex/codex-structured-journal-goal-rows.test.ts
  • src/main/codex/codex-structured-journal-goals.ts
  • src/main/codex/codex-structured-session-adapter.ts
  • src/main/codex/codex-structured-thread-goal.test.ts
  • src/main/codex/codex-structured-thread-goal.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter-router.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.ts
  • src/main/native-chat/agent-session-wire/unhandled-provider-frame.ts
  • src/main/runtime/rpc/methods/structured-agent-session-gate-classification.test-fixture.ts
  • src/main/runtime/rpc/methods/structured-agent-session-rpc.test-fixture.ts
  • src/main/runtime/rpc/methods/structured-agent-session-schemas.ts
  • src/main/runtime/rpc/methods/structured-agent-session-thread-goal.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session.ts
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/NativeChatComposerActions.tsx
  • src/renderer/src/components/native-chat/NativeChatComposerField.tsx
  • src/renderer/src/components/native-chat/NativeChatComposerGoalChip.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageList.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRow.test.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRow.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/NativeChatThreadGoalBanner.test.tsx
  • src/renderer/src/components/native-chat/NativeChatThreadGoalBanner.tsx
  • src/renderer/src/components/native-chat/native-chat-composer-types.ts
  • src/renderer/src/components/native-chat/native-chat-thread-goal-presentation.ts
  • src/renderer/src/components/native-chat/native-chat-thread-goal-rows.test.ts
  • src/renderer/src/components/native-chat/native-chat-thread-goal-rows.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
  • src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-options.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-thread-goal.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/agent-session-journal-schemas.test.ts
  • src/shared/agent-session-journal-schemas.ts
  • src/shared/agent-session-journal-types.ts
  • src/shared/agent-session-thread-goal.test.ts
  • src/shared/agent-session-thread-goal.ts
  • src/shared/agent-session-wire.ts
  • src/shared/native-chat-types.ts
  • src/shared/rpc-contract/structured-agent-session-params.ts
  • src/shared/structured-agent-session-composer.test.ts
  • src/shared/structured-agent-session-composer.ts
  • src/shared/structured-agent-session-projection.ts
  • tests/e2e/cross-version-wire/structured-agent-session-host-fixture.ts
  • tests/e2e/cross-version-wire/structured-agent-session-surface-manifest.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +60 to +63
} catch (error) {
await withdrawObjective()
throw error
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep the objective row when the provider call throws; the goal may already be active.

The adapter contract says a throw from changeThreadGoal leaves the effect unknown. changeCodexThreadGoal rethrows timeouts and transport losses, and Codex can already have set the goal when that happens. An active goal starts provider work at once. This catch block still tombstones the objective row. The provider can then work toward a goal that the transcript no longer shows as "Sent as goal". A retry reruns the change because replay returns null for non-succeeded outcomes. That rerun re-upserts a row that was already tombstoned.

Withdraw the objective only when the provider explicitly refuses (!result.ok). On a throw, keep the row and rethrow, so the mutation records an unknown outcome. Update the test "removes the objective when the provider request fails outright" to match.

🐛 Proposed fix
-  let result: Awaited<ReturnType<typeof ctx.adapter.changeThreadGoal>>
-  try {
-    result = await ctx.adapter.changeThreadGoal({
-      sessionId: ctx.sessionId,
-      fence: ctx.fence,
-      change
-    })
-  } catch (error) {
-    await withdrawObjective()
-    throw error
-  }
+  // A throw leaves the provider effect unknown; the goal may be active, so keep the objective.
+  const result = await ctx.adapter.changeThreadGoal({
+    sessionId: ctx.sessionId,
+    fence: ctx.fence,
+    change
+  })

@pullfrog pullfrog 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.

Important

A new client talking to an older remote host hides every Codex goal row from the transcript while the replacement banner cannot render, so goal state disappears entirely for that chat. One regression plus two nits; details inline.

Reviewed changes

  • Typed goal state. Journal status rows carry an optional threadGoal ({ state: 'set', goal } | { state: 'cleared' }); currentAgentSessionThreadGoal derives the latest transition by sequence and agentSessionThreadGoalElapsedSeconds extrapolates only while a goal is active and a turn runs.
  • Codex writer / revisions. thread/goal/updated|cleared frames are parsed into the typed snapshot; counter-only updates revise the existing row in place (same identity) under a 30s throttle via accountingOutgrew, and durable state reseeds accounting from the journal.
  • agentSession.threadGoal session action. Set/pause/resume/clear flow through the standard admission, ledger, and journal path; a set writes the objective as a sentAs: 'goal' user row before the provider request and tombstones it when the provider refuses or the request throws.
  • Wire additions. Optional threadGoal on the agentSession.options result (only where supportsThreadGoal), an open schema for sentAs and goal state, a 4000-char objective cap, and the method-count / cross-version fixtures.
  • Renderer. Goal banner above the composer, goal mode via /goal (picker interception, chip, placeholder), the "Sent as goal" message marker, and omission of goal rows from structured transcripts.

ℹ️ Nitpicks

  • use-native-chat-composer-submit.ts:47 compares item.name !== 'goal' verbatim, while isStructuredAgentSessionGoalCommand lowercases through commandParts; a host catalog reporting Goal would miss goal mode. Curated catalogs use lowercase, so this is cosmetic.
  • isAgentSessionThreadGoalOpen (src/shared/agent-session-thread-goal.ts:72) is exported but only referenced by its own test — the banner uses nativeChatThreadGoalStatusLabel(...) === null instead. Either use it or drop it until the mobile banner lands.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

const messages = useMemo(() => {
const projected = projectNativeChatTaskListFrames(projectMessages(session.messages))
// Structured sessions show goal state in the banner above the composer.
return journalItems ? omitNativeChatThreadGoalRows(projected) : projected

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.

The omit gate keys on journalItems, which is always a truthy array for a structured session, not on whether the host can supply the replacement banner. A new client connected to an older remote host therefore strips every grey Goal set:/Goal cleared: row while controller.threadGoal is null, so goal state vanishes entirely — the mixed-version case the wire-compat rules treat as normal.

Technical details
# Goal rows are hidden even when no banner replaces them

## Affected sites
- `src/renderer/src/components/native-chat/NativeChatMessageList.tsx:141` — filter applied whenever `journalItems` is present, which is every structured session.
- `src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx:326` — banner renders only when `controller.threadGoal?.goal` is set.
- `src/renderer/src/components/native-chat/use-structured-agent-session-thread-goal.ts:55` — returns null when the options result omits `threadGoal`.
- `src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts:186` — host reports `threadGoal` only when `supportsThreadGoal` exists.

## Required outcome
- A structured Codex session on a host that cannot report the goal keeps its goal rows visible (or otherwise surfaces goal state) instead of losing both.

## Suggested approach (optional)
- Gate the omit on the same predicate that gates the banner (e.g. pass `threadGoal !== null` / a `showThreadGoalBanner` flag), so rows are suppressed only where the banner exists.

## Open questions for the human (optional)
- If hiding rows on old hosts is intentional, is that acceptable given `/goal` still falls back to prose there?

…ver a lost goal-change response

- A set while the journal records a goal (any status) clears it before setting,
  so the new goal starts with its own time and token counters instead of
  rewriting the old goal's objective in place.
- The threadGoal plan answers an unknown outcome from the goal the journal
  records and reruns otherwise, so one request timeout no longer refuses every
  later Clear/Pause/Resume as unknown for the mounted session.
- The goal-mode chip says "Exit goal mode"; "Clear goal" stays the banner's
  action on the provider goal.
- A typed bare /goal on Enter enters goal mode, the same as picking it.
- The renderer reads the goal off the tail of its ordered snapshot; the host's
  unordered map keeps the by-sequence reader.
- Drop the composer's duplicate in-flight guard; the goal controller already
  serializes changes.
- Pin that a counter-only revision reaches a subscriber's live page under its
  original sequence.

@pullfrog pullfrog 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.

ℹ️ No new issues in this delta. The two commits since the prior review are a focused, well-tested fix; the earlier mixed-version omission concern is still open in its inline thread.

Reviewed changes — re-reviewed the delta since the prior pullfrog review (56db245).

  • Goal replacement clears first: a set on a thread whose journal already records a goal (any status) now emits thread/goal/clear before thread/goal/set, so the new goal starts from zero counters instead of inheriting the old goal's timer and token count. The clear is sent inline and a refused clear stops before the set, leaving the old goal intact.
  • Lost-response recovery: agentSession.threadGoal now sets recoverUnknownFromDurableState and a rerunWhenReplayMissing predicate. An unknown outcome is answered from the journal via journalRecordsThreadGoalChange (clear → goal is null, status → status matches, set → recorded objective matches while active); anything else reruns. Reruns upsert the same objective row, which outranks its tombstone, and per-session serialization keeps concurrent changes ordered.
  • Rendered-snapshot goal read: currentAgentSessionThreadGoal scans a rendered snapshot backwards instead of taking the max sequence; the unordered variant moved to currentAgentSessionThreadGoalBySequence for the host journal map. Safe because the renderer reducer always sorts items by sequence and revisions keep their sequence.
  • Composer goal mode: the bare /goal token now enters goal mode like the picker does; the chip label became "Exit goal mode" so it is not confused with the banner's "Clear goal"; the submit guard now relies on the controller's pending serialization.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: af1d9b26-4d6f-4548-bcb9-5640b0b0a24f

📥 Commits

Reviewing files that changed from the base of the PR and between 56db245 and 8563f69.

📒 Files selected for processing (15)
  • src/main/codex/codex-structured-journal-goal-revision.test.ts
  • src/main/codex/codex-structured-session-adapter.ts
  • src/main/codex/codex-structured-thread-goal.test.ts
  • src/main/codex/codex-structured-thread-goal.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.ts
  • src/renderer/src/components/native-chat/NativeChatComposerGoalChip.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/agent-session-thread-goal.test.ts
  • src/shared/agent-session-thread-goal.ts
  • src/shared/structured-agent-session-composer.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/renderer/src/components/native-chat/NativeChatComposerGoalChip.tsx
  • src/renderer/src/i18n/locales/en.json

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

Comment on lines +42 to +44
for (const request of codexThreadGoalRequests(session.threadId, change, replacesGoal)) {
await session.connection.request(request.method, request.params, { timeoutMs })
}

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

A refused set after a successful clear is reported as a plain refusal.

When replacesGoal is true, the loop sends thread/goal/clear first. If thread/goal/set then throws CodexAppServerRequestError, the function returns { ok: false, rejected }. The adapter contract says rejected means the provider refused the change. In this case the provider already cleared the previous goal, including its status and usage counters.

performThreadGoalChange tombstones the objective and shows the refusal message. The user reads this as "nothing changed," but the old goal has disappeared from the goal bar.

Tell the caller when a replacement cleared the old goal before it was refused. For example, add the fact to the rejected message so the user is not told nothing changed.

Proposed fix
-  try {
-    for (const request of codexThreadGoalRequests(session.threadId, change, replacesGoal)) {
-      await session.connection.request(request.method, request.params, { timeoutMs })
-    }
-    return { ok: true }
-  } catch (error) {
-    if (isCodexAppServerRequestError(error)) {
-      return { ok: false, rejected: error.message }
-    }
-    throw error
-  }
+  let cleared = false
+  try {
+    for (const request of codexThreadGoalRequests(session.threadId, change, replacesGoal)) {
+      await session.connection.request(request.method, request.params, { timeoutMs })
+      cleared ||= request.method === 'thread/goal/clear'
+    }
+    return { ok: true }
+  } catch (error) {
+    if (isCodexAppServerRequestError(error)) {
+      const rejected = cleared
+        ? `${error.message} (the previous goal was already cleared)`
+        : error.message
+      return { ok: false, rejected }
+    }
+    throw error
+  }

Comment on lines +107 to +116
// A lost response is answered from the journal, which the provider keeps
// current; otherwise the change runs again, which is safe for every kind.
recoverUnknownFromDurableState: true,
replay: (ctx, outcome) =>
outcome.status === 'succeeded' ||
(outcome.status === 'unknown' &&
journalRecordsThreadGoalChange(ctx.journal.threadGoal(), params.change))
? value
: null,
rerunWhenReplayMissing: () => true

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

An unknown set reruns and repeats provider work if the goal is no longer active.

The comment says a rerun "is safe for every kind." A rerun is not safe for set. If the set response is lost, the provider may already have started the goal, because an active goal starts work at once.

Before recovery runs, the user can pause the goal, or the provider can finish it (complete). journalRecordsThreadGoalChange then returns false, so rerunWhenReplayMissing runs performThreadGoalChange again. That rerun computes replacesGoal: true, sends thread/goal/clear, and sets the same objective as a new active goal. The provider runs the same work twice, for example editing files or running commands again.

For set, treat the change as applied when the journal holds a goal with the same objective, whatever its status. Update the test at lines 258-264 to match.

Proposed fix
     case 'set':
-      return goal !== null && goal.status === 'active' && goal.objective === change.objective
+      // Any status: a lost set may already have run, then paused or completed.
+      return goal !== null && goal.objective === change.objective
-    // A lost response is answered from the journal, which the provider keeps
-    // current; otherwise the change runs again, which is safe for every kind.
+    // A lost response is answered from the journal, which the provider keeps
+    // current; otherwise the change runs again.

… and pin goal delivery and serialization

- A bare `/goal` submitted while already in goal mode re-enters the mode instead
  of setting a goal whose objective is the literal text "/goal".
- The counter-only revision pin now drives the host's own event sink bound to a
  real journal, so it goes red when the publish after a lifecycle transition is
  dropped; the previous fake sink never published.
- Pin that a set which threw after journaling its objective puts that objective
  back exactly once when the ledger reruns the same operation id.
- Cover the goal controller hook: absent without host support, the loaded window
  wins over the host's answer, a second change while one is unsettled answers
  false without a request, and a refused change frees the next one.

@pullfrog pullfrog 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.

ℹ️ No new issues in this delta. The commit since the prior review is a one-line behavior fix plus test hardening; the earlier mixed-version omission concern is still open in its inline thread.

Reviewed changes — re-reviewed the delta since the prior pullfrog review (8563f69).

  • Bare /goal is always the entrance: the composer submit hook now tests for a bare /goal token before the active branch, so typing /goal while already in goal mode re-enters the mode (keeping the chip) instead of setting a goal whose objective is the literal text /goal. active requires threadGoal !== undefined, so the new first branch cannot mask the normal setGoal path; no-goal hosts still fall through to sendStructured/sendPty unchanged, and the bare-token branch was never disabled-gated before or after.
  • Goal-delivery pin now drives the real sink: the counter-only revision test binds the host's own createDeferredStructuredAgentSessionEventSink to a real journal and captures the page published to a caught-up subscriber, so a dropped publish after a lifecycle transition goes red (the previous fake sink never published).
  • Objective revival pin: a set that throws after journaling its objective is covered — the ledger rerun of the same operation id revives the tombstoned sentAs: 'goal' row exactly once rather than appending a duplicate.
  • Goal controller hook coverage: new tests pin null-without-host-support, window-over-host-answer precedence, a second in-flight change answering false without a request, and a refused change freeing the next one. Assertions are exact and able to fail.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Preserve edits made while setting a goal. · use-native-chat-composer-submit.ts:48-95

src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts:48-95
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve edits made while setting a goal.

threadGoal.pending does not disable the editor. If the user edits the draft while setObjective is pending, an accepted response clears that later draft and caret. The structured-send hook already checks whether the composition changed before clearing.

Suggested fix
-import { useCallback, useMemo, useState } from 'react'
+import { useCallback, useMemo, useRef, useState } from 'react'
...
   const threadGoal = structuredTransport?.threadGoal
   const [entered, setEntered] = useState(false)
+  const draftRef = useRef(draft)
+  const caretRef = useRef(caret)
+  draftRef.current = draft
+  caretRef.current = caret
   const active = entered && threadGoal !== undefined
...
   const setGoal = useCallback(() => {
     const objective = draft.trim()
+    const submittedDraft = draft
+    const submittedCaret = caret
     if (!threadGoal || !structuredTransport || objective === '') {
       return
     }
...
     void threadGoal.setObjective(objective).then((accepted) => {
       if (accepted) {
         structuredTransport.onError(null)
-        setHistory((previous) => pushHistory(previous, draft))
+        setHistory((previous) => pushHistory(previous, submittedDraft))
+        if (
+          draftRef.current !== submittedDraft ||
+          caretRef.current !== submittedCaret
+        ) {
+          return
+        }
         setDraft('')
         setCaret(0)
         setEntered(false)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2c71e174-ea28-42a5-8c48-392e6f11ac06

📥 Commits

Reviewing files that changed from the base of the PR and between 8563f69 and e3c5cbe.

📒 Files selected for processing (5)
  • src/main/codex/codex-structured-journal-goal-revision.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-thread-goal.test.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

…al-mode drafts honest

- The goal bar offers Resume on a blocked or usage-limited goal, which the
  provider resumes exactly as it resumes a paused one; a goal whose token budget
  is spent still offers only Clear. The rule lives beside the other goal facts
  in shared code so every reader answers it the same way.
- A `/goal <text>` typed inside goal mode sets the objective `<text>`, as it
  does outside goal mode, instead of a goal whose objective is the literal
  command.
- Setting a goal is a host round trip; a draft edited while it was in flight is
  no longer wiped when the goal lands, matching every other host command.
- Pin that a lost status-change response is read as applied only when the
  recorded goal is in that status, that a cleared row in the loaded window
  outranks the host's earlier answer, and that the PTY lane is untouched.

@pullfrog pullfrog 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.

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes — re-reviewed the delta since the prior pullfrog review (e3c5cbe).

  • Stalled and usage-limited goals are resumable. agentSessionThreadGoalStatusChange centralizes the status-to-control mapping; the banner now offers Resume for blocked and usageLimited (both mapped to { kind: 'status', status: 'active' }) while a budgetLimited or complete goal keeps no status control. The provider request path already handles a status-only thread/goal/set.
  • A goal-mode draft edited mid-flight survives. useNativeChatComposerSubmit records the submitted draft in a ref and only clears the draft, caret and goal-mode flag when that draft is still current when setObjective resolves, matching the sibling structured-send hook.
  • A typed /goal … inside goal mode names the objective. structuredAgentSessionGoalObjective strips the command prefix so the host sets the named objective; a bare /goal is still caught earlier as the mode entrance.
  • Test hardening. Banner resume/clear matrix, the objective parse, the preserved in-flight draft, the PTY-lane passthrough, the clear-in-window-over-host-answer precedence, and the status replay predicate.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

>
<Pause className="size-3.5" />
</GoalAction>
) : statusChange === 'active' ? (

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.

usageLimited and budgetLimited both render the label Goal limited (native-chat-thread-goal-presentation.ts:15-17), but this branch now offers Resume for usageLimited only. A user looking at a Goal limited bar cannot tell why one is resumable and the other is not, even though the saved journal rows already distinguish usage limit from token budget spent (codex-goal-journal-rows.ts:24-25). Consider giving budgetLimited its own label and i18n key.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4458f82d-f3d4-41ff-84a3-e4752889f915

📥 Commits

Reviewing files that changed from the base of the PR and between e3c5cbe and 4ec725b.

📒 Files selected for processing (10)
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts
  • src/renderer/src/components/native-chat/NativeChatThreadGoalBanner.test.tsx
  • src/renderer/src/components/native-chat/NativeChatThreadGoalBanner.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-thread-goal.test.tsx
  • src/shared/agent-session-thread-goal.test.ts
  • src/shared/agent-session-thread-goal.ts
  • src/shared/structured-agent-session-composer.test.ts
  • src/shared/structured-agent-session-composer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +122 to +123
const command = commandParts(text)
return command?.name === 'goal' ? command.argument : text.trim()

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,180p' src/shared/structured-agent-session-composer.ts
sed -n '60,145p' src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
sed -n '35,100p' src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts

Repository: stablyai/orca

Length of output: 11976


🏁 Script executed:

rg -n -C 5 "dispatchNativeChatStructuredComposerText|structuredAgentSessionGoalObjective|setThreadGoalObjective|setObjective|threadGoal" src

Repository: stablyai/orca

Length of output: 42720


🏁 Script executed:

cat -n src/renderer/src/components/native-chat/native-chat-structured-composer-dispatch.ts
sed -n '35,95p' src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.ts
rg -n -C 4 "objective" src/main/native-chat/agent-session-wire src/shared/agent-session-wire.ts src/renderer/src/components/native-chat | head -n 180

Repository: stablyai/orca

Length of output: 22688


Parse multiline /goal objectives before submission.

For /goal ship\nand verify, commandParts returns null because its argument pattern does not match an interior newline.

In goal mode, structuredAgentSessionGoalObjective passes the trimmed draft, including /goal, to threadGoal.setObjective. In normal dispatch, the draft is not recognized as a host command and is sent as ordinary message text. These are different failures.

Accept multiline arguments in commandParts. Add coverage for both goal-mode submission and normal /goal dispatch.

Suggested fix
-  const match = /^\/([^\s]+)(?:\s+(.*))?$/.exec(text.trimEnd())
+  const match = /^\/([^\s]+)(?:\s+([\s\S]*))?$/.exec(text.trimEnd())

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA on head 4ec725b20b (4ec725b20b9dccaa98af21c7b8bcc2cb65057b98). Isolated dev instance only (CDP 9333, renderer 5174). Structured Codex chat in folder workspace goal-ws.

Scenario Result What I saw
A1 goal picker Pass Typing / opened the command list, including /goal “Set or view the goal”.
A2 goal-mode chip Pass Picking /goal showed a “Goal” chip (aria-label “Exit goal mode”) beside Attach, and the placeholder “Describe your goal, define measurable outcomes for best results”.
A3 chip hover Pass Hover hid the goal icon and showed the X (display: block). Tooltip text was “Exit goal mode”.
A4 typed /goal Pass Clicking the chip returned the “Send a message…” placeholder. Typing /goal and pressing Enter entered goal mode again (chip + goal placeholder). The saved image is that second typed enter; the first one was the same state in the accessibility tree before the first send.
B1 set a goal Pass, with a timing note Enter sent the proof-file objective. The message had a “Sent as goal” caption. The bar read “Pursuing goal … • 9s”. The composer showed “Stop the agent” and Codex worked on its own. It wrote goal-proof.txt containing goal reached, marked the goal complete, and the bar disappeared. The shot ~15s later is that completed chat, so it does not show a second pursuing timestamp. On the next goal, while a turn was running, the bar was sampled at 1s, then 2s, then 4s, then 5s.
B2 no grey rows Pass Transcript text had no “Goal set” and no “Codex ·”.
C1 pause Pass “Pause goal” changed the bar to “Paused goal … • 23s”. Three seconds later it was still 23s. The button became “Resume goal”.
C2 resume Pass “Resume goal” changed it back to “Pursuing goal … • 23s”, and “Pause goal” returned.
D1 replace Pass Before send the bar was the README objective at 25s. After sending the replacement objective it was “Pursuing goal Write the single word replacement into replaced-goal.txt … • 0s”.
E1 relaunch Pass I paused that replacement goal before quit so it would still be open (paused at 24s). Quit and relaunch of the same profile restored “Paused goal Write the single word replacement into replaced-goal.txt and do not mark the goal complete. • 24s” on Codex Chat. Light theme shot included.
F1 history into a new chat Pass Second fresh profile (/tmp/qa-8159b), same flags, restarted. Agent Session History listed Codex session 01a0cd04 for this folder. “Resume in New Chat” opened a Codex Chat whose bar was the same paused objective at 24s.
G1 clear Pass “Clear goal” removed the bar immediately. After another relaunch, that Codex Chat came back with the transcript and no goal bar (no “Pursuing goal” / “Paused goal”, and no data-native-chat-thread-goal node).

“Show full goal” was present as an icon button. I did not click expand/collapse.

Light theme: B1 light is the completed transcript after the first goal finished. E1 light is the restored paused bar.

A1 goal picker
A2 goal-mode chip
A3 chip hover
A4 typed goal
B1 about 3s, pursuing 9s
B1 later, goal complete and bar gone
Later goal while the elapsed time was ticking
B1 light theme, completed transcript
B2 no grey goal-set rows
C1 paused
C2 resumed
D1 replaced goal
E1 relaunch
E1 relaunch, light theme
F1 history opened into a new chat
G1 immediately after Clear goal
G1 after relaunch, bar still gone

…n a live revision lands below it

A live revision of a row keeps that row's original sequence. When the row is
older than the client's loaded window, the shared reducer merged it in and it
became the load-older anchor, so paging `before` it skipped every row between.
A goal's counter-only revisions during a long goal turn reach any client that
attached after the goal row left its window, so a reopened chat lost rows on
scroll-back.

The reducer now admits live rows only at or above the window's oldest row
while older rows remain on the host; the journal keeps the revision and the
page reader serves it once the window reaches the row. With nothing older on
the host the window is the whole journal, so a row below the head is admitted
as before.

Also drain accepted provider events before a goal set reads the journal to
decide whether it replaces a recorded goal.

@pullfrog pullfrog 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.

ℹ️ No new issues in this delta. The one commit since the prior pullfrog review is a focused, well-tested fix. The two earlier findings — the mixed-version goal-row omission and the shared Goal limited label — are untouched by it and remain open in their threads.

Reviewed changes — re-reviewed the delta since the prior pullfrog review (4ec725b).

  • Load-older anchor kept on the loaded window. liveItemsWithinWindow in structured-agent-session-reducer.ts now admits a live batch's rows only at or above the window's oldest sequence while hasOlder is set. A revision of an older row keeps its original sequence, so admitting it had moved the load-older anchor below the window and before paging skipped every row between. The journal keeps the revision and the page reader serves it once the window reaches the row; with nothing older on the host the window is the whole journal, so a revived row below the head is still admitted.
  • A goal set drains accepted provider events first. performThreadGoalChange awaits ctx.flushStreamedEvents() before reading ctx.journal.threadGoal() to decide replacesGoal, so a goal the host accepted but has not journaled yet still counts as a replacement instead of a fresh set.
  • Tests. New retention cases pin the preserved anchor, the page-reader revision, an in-window revision and the hasOlder === false revival; a deferred-sink case pins the replacesGoal: true decision. All fail against the pre-commit code.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready to merge at 7280c2d07c

Six adversarial review loops ran on this PR (each loop targeted the previous loop's changes; the last two returned clean with no edits), plus an opening and closing readiness pass and a real-app Electron QA pass (see the QA comment above, captured at 4ec725b20b; the two later commits changed no UI). CI is green and the branch merges cleanly onto current main.

What the loops changed (all pushed to this branch)

  • Replacing a goal now clears the old one first (8563f699b3). Setting a new objective while a goal exists used to rewrite the existing goal in place, so the new goal inherited the old goal's time and token counters. QA confirmed the timer now restarts at 0s on replace (D1).
  • A lost goal-change response no longer wedges the controls (8563f699b3). One request timeout used to leave Clear/Pause/Resume refused as "unknown" until the session view remounted. The host now answers a replay from the goal the journal records, and reruns when nothing was recorded.
  • Goal-mode chip copy now reads "Exit goal mode"; "Clear goal" is only the bar's action on the provider goal (8563f699b3).
  • Typed /goal behaves like the picker: bare /goal enters goal mode; inside goal mode, a bare /goal re-enters rather than setting the literal text, and /goal <text> sets <text> (8563f699b3, e3c5cbeab9, 4ec725b20b).
  • Resume is offered for blocked and usage-limited goals, which the provider resumes the same way as a paused one; a spent token budget still offers only Clear (4ec725b20b).
  • A draft typed while a goal set is in flight is kept instead of being wiped when the goal lands (4ec725b20b).
  • Scroll-back no longer skips rows in long goal sessions (7280c2d07c). A counter-only goal revision keeps its original row position; when that row was older than the client's loaded window, the shared reducer adopted it as the "load older" anchor and paging skipped every row between. Live rows below the loaded window are now left for the page reader while older rows remain on the host. This is a shared reducer fix and also applies to mobile scroll-back.
  • Goal set drains accepted provider events before deciding whether it replaces a goal (7280c2d07c).
  • Test hardening: the counter-revision delivery pin now drives the host's real event sink (the earlier pin passed with publishing removed), the goal controller hook has its own tests, and a rerun after a withdrawn objective is pinned to restore the row exactly once.

Readiness passes

Opening pass (at 56db245f6d): PASS, two P2 candidates, both fixed above (lost-response wedge) or accepted as residual (goal controls appear for any live Codex session; on a Codex build without goals, /goal gets the provider's own refusal text instead of being sent as prose).
Closing pass (at 4ec725b20b): PASS WITH RISK, one P2 (the scroll-back anchor), fixed in 7280c2d07c and re-reviewed clean.

Known behaviors left as-is (worth a product decision, not blockers)

  • Setting a new goal while one exists replaces it immediately, with no "Replace current goal?" confirmation. The previous goal's counters are discarded by design.
  • Pressing Enter in goal mode while a previous goal change is still in flight does nothing visible; the draft stays and the next Enter works once the first settles.
  • A multi-line objective pasted after /goal inside goal mode is taken literally (the shared command parser is single-line for every command).
  • If a goal request times out but the provider applied it, the retry succeeds from the journal, but the transcript will not show that objective as a "Sent as goal" message; the bar still shows it.
  • A reopened chat with more than 300 rows since the goal was set refreshes the bar's reported time/token base at the next turn boundary or on scroll-back rather than every 30s; the ticking timer itself is unaffected.

Design notes for the author

  • The bar is derived client-side from the latest goal row in the loaded window, with a whole-journal answer from agentSession.options as the fallback. An alternative is for the host to publish the derived current goal alongside each subscribe frame and drop the client-side precedence; that keeps the journal as the source but moves derivation to the host. Left as the author's call since it changes the frame shape.
  • The objective is journaled as a user message before the provider confirms, which is why the withdraw-on-refusal and restore-on-rerun paths exist. The alternative is to show only the provider's own "Goal set" transition row. Kept the author's design.

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d4850194-ec12-4265-9403-59eca104e677

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec725b and 7280c2d.

📒 Files selected for processing (4)
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-thread-goal.ts
  • src/shared/structured-agent-session-item-retention.test.ts
  • src/shared/structured-agent-session-reducer.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.

requestedCursor: { epoch: 'epoch-a', sequence: 200 },
page: page(
[{ ...item(50), revision: 2 }, ...Array.from({ length: 149 }, (_, i) => item(i + 51))],
false

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep pagination open while rows 1–49 remain.

The test says the host has rows 1–199 before the loaded window. This page supplies only rows 50–199, but hasOlder: false makes the reducer stop paging. Set hasOlder to true and update the assertion, or include rows 1–49 in this page.

Proposed test correction
-        false
+        true
...
-    expect(older.hasOlder).toBe(false)
+    expect(older.hasOlder).toBe(true)

if (!head || !state.hasOlder) {
return incoming
}
return incoming.filter((item) => item.sequence >= head.sequence)

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- reducer outline ---'
ast-grep outline src/shared/structured-agent-session-reducer.ts
printf '%s\n' '--- reducer target ---'
sed -n '90,230p' src/shared/structured-agent-session-reducer.ts
printf '%s\n' '--- helper and reducer references ---'
rg -n -C 3 'liveItemsWithinWindow|older-page|hasOlder|sequence' src --glob '*.{ts,tsx}' | head -n 240

Repository: stablyai/orca

Length of output: 44914


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions

Length of output: 28639


🏁 Script executed:

set -eu
sed -n '100,220p' src/shared/structured-agent-session-reducer.ts
printf '%s\n' '--- references ---'
rg -n -C 4 'liveItemsWithinWindow|older-page|hasOlder' . --glob '!node_modules' --glob '!dist' --glob '!build' | head -n 300

Repository: stablyai/orca

Length of output: 32133


🏁 Script executed:

set -eu
printf '%s\n' '--- history reader references ---'
rg -n -C 5 'readAgentSessionHistory|direction.*before|requestedCursor|older-page' src tests/e2e mobile --glob '*.{ts,tsx}' | head -n 320
printf '%s\n' '--- delayed owner test ---'
sed -n '110,210p' tests/e2e/structured-agent-session-read-owner.unit.test.ts

Repository: stablyai/orca

Length of output: 41692


🏁 Script executed:

set -eu
printf '%s\n' '--- history page implementation ---'
ast-grep outline src/main/native-chat/agent-session-wire/agent-session-history-page.ts
sed -n '1,260p' src/main/native-chat/agent-session-wire/agent-session-history-page.ts
printf '%s\n' '--- delayed test continuation ---'
sed -n '195,285p' tests/e2e/structured-agent-session-read-owner.unit.test.ts
printf '%s\n' '--- read-owner implementation references ---'
rg -n -C 5 'getStructuredAgentSessionReadOwner|direction.*before|older-page|delayedOlder|requestedCursor' src tests/e2e --glob '*.{ts,tsx}' | head -n 360

Repository: stablyai/orca

Length of output: 41324


Reconcile live revisions with in-flight older-page reads.

When readAgentSessionHistory snapshots an older page before a live revision arrives, it can return the older revision. liveItemsWithinWindow then drops the live revision because its original sequence is below head.sequence. The older-page branch can accept the stale page because its head check does not advance, leaving the reducer without that live update. Retain skipped revisions until page merge, or invalidate and retry the affected older-page request.

@brennanb2025
brennanb2025 merged commit 563dd54 into main Sep 23, 2026
32 checks passed
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Layout check on 7280c2d07c (7280c2d07c060de18d3414dd7954319d065a1ef3). Isolated dev instance, structured Codex chat in folder workspace goal-ws.

The goal bar sits in the same band above the composer as the background-task strip. This frame is an active goal ("Pursuing goal …") directly under an expanded shell row (/bin/zsh -lc 'sleep 90', "1 shell command — working"). The thread just above shows the subagent that same goal started ("Ran 1 subagent", completed).

Goal bar under a live shell, with the subagent in the thread

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