Skip to content

fix(conn-server): Pass 4 steer app notes and PR watch merge wakes, as T3 - #280

Closed
nckrtl wants to merge 10 commits into
fix/conn-server-audit-pass4from
fix/conn-server-audit-pass4-steer-watch
Closed

nckrtl wants to merge 10 commits into
fix/conn-server-audit-pass4from
fix/conn-server-audit-pass4-steer-watch

Conversation

@nckrtl

@nckrtl nckrtl commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Fixes Pass 4 findings 4.6 and 4.3 of the Conn Server port audit. Stacked on #276: the base is fix/conn-server-audit-pass4. One commit per finding. Each acceptance test was run failing without its fix and passing with it.

4.6: a steer carries a changed MCP app note (b25072b032)

Crates: conn-provider, conn-engine, conn-provider-codex, conn-provider-claude.

Change:

  • SteerInput gets app_context, and the engine fills it.
  • Codex: turn/steer takes no additionalContext. As T3's steerTurn does, the session sends each note the native thread has not been sent, as quoted user input (<external_KEY>text</external_KEY>) before the message. It records notes only after a steer succeeds; a turn start records what its additionalContext sent.
  • Claude: a steer compares with what the running turn offered, else with the history, as T3 does.

Tests:

  • session::tests::a_steer_carries_a_changed_app_note_once (codex, fake app-server inputs): an unchanged note is not resent, a changed one goes once before the message, and a refused steer resends it on the retry. With the note-sending stubbed out, the changed input lacks the note.
  • interrupt_tests::mcp_app_notes_reach_the_claude_prompt_until_a_turn_takes_them_in gains T3's steer steps: an unchanged note is skipped, a changed one goes once. Without the steer change it fails on PROJ-44.

4.3: an external merge wakes the thread; the agent's own merge stays quiet (8dd96cfb9d)

A full port of T3's PullRequestWatchReactor merge path, in rust-port order: T3's behaviour and tests first, then the smallest Rust design.

T3 Rust
isChangeRequestCloseCommand, changeRequestsClosedBy (sourceControlDefinitions.ts) conn_source_control::close_commands::{is_close_command, closed_by}. tools/gen-upstream.mjs generates the host patterns (JS \d and \w made ASCII; lookaround refused)
commandIndicatesFailure, toolOutputIndicatesFailure (toolOutput.ts) close_commands::{command_failed, output_indicates_failure}
engine.streamDomainEvents (command items, run updates) Engine::subscribe_command_events: paged from the event log after each commit, behind a bounded channel
agentEnds, finished, readThreadWatches Watcher::{agent_event, ended_by_agent, read_thread_watches} plus the agent_events feed task. Kept-item memory is capped (1024 finished ids, 64 open commands per thread)
finished / pullRequestWatchEndMessage Watcher::finished, watch::end_message. Closed PRs now use T3's text
endMergedSnapshots; merged snapshot no longer in endsWithoutRead the failure branch of read_group
mergeCommitSha, mergedBy in the PR detail detail.rs, only when the host gives them

Tests:

  • close_commands::tests::{closes_what_t3_finds, reads_failure_output_as_t3} compare with T3's own answers. The generator runs T3's functions on 30 commands (T3's test cases plus other hosts and negatives) and 26 outputs.
  • the_command_feed_carries_command_items_and_run_updates (conn-engine).
  • agent_merge_commands_reach_the_watch_loop: running, then completed, sent once; a failure reported as completed counts as failed; run end; other commands ignored.
  • a_watched_pull_request_wakes_its_thread_when_its_checks_or_comments_change, extended:
    • An external merge sends one wake: "…was merged into main by octocat as 3b2f958…", outcome completed, summary #7: merged, stopped watching, watch cleared. The next sweep sends nothing.
    • A merged link the host cannot read ends from its snapshot, with the wake.
    • The thread's own gh pr merge 7 ends the watch with no wake.
    • A failed merge command still wakes.
    • Forcing finished quiet fails on the missing external wake; forcing it loud fails on the own-merge wake.

Dependency: conn-source-control now uses regex-automata (workspace dependency, already in the binary through conn-support and conn-files). The only Cargo.lock change is that edge.

Gate round 1 findings (fixed)

# Finding Commit Test Fails without the fix
1 Watch ordering: a slow host read held agent events 7c4397bd18 agent_merges_apply_during_a_held_host_read (both orders, held host response) Structural: at 8dd96cfb9d ownership changed only in Watcher::agent_event, which needs &mut Watcher and so cannot run while a pass holds it
2 A refused Claude steer kept its note recorded 3c4eabf927 mcp_app_notes_reach_the_claude_prompt_until_a_turn_takes_them_in (refusal, then retry) Shown: the retry carried no note
3 MCP pull_request_merge woke its own thread 7c4397bd18 the agentMerge steps of a_watched_pull_request_wakes_its_thread_when_its_checks_or_comments_change Structural: at 8dd96cfb9d the merge tool reported nothing to the watch
4 Feed cursor rescanned rows that matched nothing 3a8c99ba0a the_command_feed_moves_past_rows_that_match_nothing The old query had no scan position, so the cursor stayed at the last match
5 Failure text cut at UTF-8 bytes, not UTF-16 units 990c29018a reads_as_much_output_as_t3, with T3's answers, including 12,000 CJK characters then exit code: 1 Shown: the CJK case returned false
6 The 65th close command lost ownership 7c4397bd18 agent_ends::tests::commands_past_the_limit_keep_ownership Structural: the old code skipped commands past 64

Deliberate difference from T3 (finding 3). T3 wakes a thread when that thread's own agent merges its watched PR through the MCP pull_request_merge tool. That wake is noise, so Conn Server ends the watch quietly instead. The tool marks the calling thread before an immediate merge and reports the outcome after. An auto-merge is not marked: it lands later, and a later merge still wakes the thread.

Gate round 2 findings (fixed)

# Finding Commit Test Fails on 7c4397bd18
6 A refused Claude steer lost its note after the turn completed 21f7ea4ca1 completion, then refusal, then retry steps in the Claude app-note test Shown: the next turn omitted PROJ-47
7 A full read queue stopped ownership updates d136c47f7f ended_merges_never_block_the_feed Shown with the reviewed API: the feed blocked after 64 reads
8 Folding the 65th command lost its lifetime d136c47f7f agent_ends::tests::many_commands_keep_their_own_lifetimes Shown with the reviewed API: a failed folded command kept ownership
9 An MCP stack merge suppressed unrelated watches d136c47f7f own_merge_tests::a_stack_merge_names_its_repository_and_layers Structural: the reviewed tool sent any: true for a stack

Gate round 3 findings (fixed in 5a3895dfca, rebased on #276 f54a467b69)

# Finding Test Fails on d136c47f7f
4 Past 1,024 entries, AgentEnds and the feed's finished list dropped ownership many_commands_keep_their_own_lifetimes (now 1,025 commands); an_ended_merge_is_never_claimed_again Shown: command 0 lost ownership; a late update of merge 0 was claimed again
5 A Claude steer kept app note A after the app removed it the new steps in the Claude app-note test Shown: note A was not sent again when it came back

Both caps are gone. Ownership ends on failure, at run end if unfinished, or after the covering read; finished is a set that lives as long as the feed, as T3's reactor (PullRequestWatchReactor.ts). A steer that carries notes replaces the offered snapshot with the app's current notes (ClaudeAdapterV2 commitOffer); a refusal restores removed notes too, unless a newer offer followed.

Known follow-up (not fixed here): a refused steer's rollback can put a note into the previous turn's delivered history; if that turn is then interrupted and the app restores the note, the next turn skips it. The fix is to track which turn owns each snapshot.

Merge with #256: keep both the reconnect test and the app-note test in crates/conn-provider-claude/src/interrupt_tests.rs.

Checks

Run on macOS, sealed (sealedCargoEnv), on this tree:

  • cargo fmt
  • cargo clippy --workspace --all-targets -D warnings: clean.
  • node tools/gen-upstream.mjs --check: current.
  • cargo test, all passed:
Crate Tests
conn-engine 228
conn-provider 8
conn-provider-claude 83, 11 ignored
conn-provider-codex 77, 2 ignored
conn-server 377 lib + integration
conn-source-control 121

Not run: tools/check.sh. It builds the comparison binaries and decode fixture into apps/conn-server/target, outside the agreed build folder, on a host short of disk. CI runs it on Linux.

Coordination:

Model: Claude Opus 5.5, Claude Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 23, 2026
@nckrtl
nckrtl force-pushed the fix/conn-server-audit-pass4-steer-watch branch from 8dd96cf to 174b123 Compare November 23, 2026 18:43
@nckrtl
nckrtl force-pushed the fix/conn-server-audit-pass4-steer-watch branch from 174b123 to 7c4397b Compare November 23, 2026 19:21
@nckrtl
nckrtl force-pushed the fix/conn-server-audit-pass4-steer-watch branch from 7c4397b to d136c47 Compare November 23, 2026 20:10
@nckrtl
nckrtl force-pushed the fix/conn-server-audit-pass4-steer-watch branch from d136c47 to 3b2b4ce Compare November 24, 2026 00:34
nckrtl and others added 9 commits November 24, 2026 01:40
… Claude, as T3

SteerInput had no field for MCP app notes, so a note an app changed during
a turn never reached the provider until the next turn.

The engine now passes the thread's notes with each steer. Codex's
turn/steer takes no additionalContext, so as T3's steerTurn the session
sends each note the native thread has not been sent with its current text
as quoted user input before the message, and records it only after the
steer succeeds; a turn start records what its additionalContext sent.
Claude steers compare with what the running turn offered, else with the
history, as T3's steer path does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n agent's merge stays quiet, as T3

When someone else merged a watched pull request, the watch loop cleared
the watch without a wake, so an agent waiting on the merge never heard of
it. It ended every merge quietly because it could not tell the thread's
own merge from another one.

This ports T3's PullRequestWatchReactor merge path:
- close_commands (conn-source-control): isChangeRequestCloseCommand,
  changeRequestsClosedBy and commandIndicatesFailure. tools/gen-upstream.mjs
  generates the host patterns and T3's own answers for sample commands and
  outputs, which the Rust tests compare with.
- conn-engine: subscribe_command_events, every thread's committed
  command_execution items and run updates, paged from the store.
- the watch loop: agentEnds. A merge or close command marks the thread's
  watches while it runs; when it ends, the thread's watches are read at
  once, quietly for what it closed. A failed command ends nothing.
- finished: a merged or closed pull request wakes its thread with T3's
  text, naming base branch, merger and merge commit; the PR detail now
  carries mergeCommitSha and mergedBy. A merged snapshot gets one read and
  ends from the snapshot when the host cannot be read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
commandIndicatesFailure reads the first 32,768 UTF-16 units of an output.
The port cut at 32,768 UTF-8 bytes, so after 12,000 CJK characters it
missed an `exit code: 1` that T3 sees, and took a failed merge command
for the thread's own merge.

It now cuts at UTF-16 units. gen-upstream.mjs records T3's own answers for
long outputs, the CJK case among them, and a test compares with them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The feed's cursor moved only to the last matching row, so every commit
made the next read scan again all rows that matched nothing since.

The page query now captures the high water with its read and reports how
far it covered: the high water for a short page, the last row for a full
one. The feed moves its cursor there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he retry

A steer recorded its notes as offered before the SDK took the message. A
refusal, such as a full prompt queue, left them recorded, so the retry
left the note out.

The steer still records the offer as it goes out, so a turn that ends
before the SDK answers counts it, and a refusal puts back what the turn
had offered before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… as the thread's own

Gate findings on the watch's merge path:
- A slow host read held every agent event, so a sweep could wake on the
  thread's own merge before its command was seen, or end quietly after a
  merge command had failed. agent_ends.rs now holds T3's agentEnds apart
  from the loop: the command feed applies each change as it arrives, and
  only the read after a finished command waits in the loop, which then
  releases the command.
- Commands past 64 per thread fold into one entry that keeps ownership
  until the thread's reads are done, instead of being dropped.
- A merge through the MCP pull_request_merge tool marks the calling thread
  before the merge and reports its outcome after it, so its watch ends
  quietly. T3 wakes the thread there; an agent's own merge waking itself
  is noise, so this deliberately differs. An auto-merge is not marked: it
  lands later and wakes the thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…even after the turn completed

Round-2 gate finding on #280: a steer the SDK refused after its turn had
completed left its notes in the history, so the next turn omitted them.

Each message that carries notes is now an offer with an id until the SDK
answers. A refusal takes back that offer's notes, in the turn's offer and in
a history the completed turn wrote them to, unless a newer offer replaced
them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r block the feed, stack merges name their layers

Round-2 gate findings on #280:
- Ended merge commands no longer push reads into a bounded channel the
  feed waits on. AgentEnds keeps the pending reads, one per thread, and
  wakes the watch loop, so ownership updates never stop behind a slow read.
- Each command is its own entry again, released on its own failure or
  completed read. Past 64 nothing folds; a thread keeps up to 1024 at once.
- An MCP merge names its repository and the pull requests it merges: the
  target and, for a stack, the layers in expectedStackHeads. It no longer
  marks every pull request of the thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…24 commands, a steer replaces Claude's offered notes

- AgentEnds and the command feed's finished set drop their 1,024 caps. Ownership now ends
  only on failure, at run end if unfinished, or after the covering read; the finished set
  lives as long as the feed (PullRequestWatchReactor's agentEnds and finished).
- A Claude steer that carries notes replaces the turn's offered snapshot with the app's
  current notes, so a note the app removed is sent again when it returns
  (ClaudeAdapterV2 commitOffer). A refusal restores removed notes too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nckrtl
nckrtl force-pushed the fix/conn-server-audit-pass4-steer-watch branch from 3b2b4ce to 5a3895d Compare November 24, 2026 00:40
# Conflicts:
#	apps/conn-server/crates/conn-engine/src/streams.rs
#	apps/conn-server/crates/conn-provider-codex/src/session.rs
@nckrtl

nckrtl commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

Included in the merge train #327 (merged as ee7b1f9). Closing.

@nckrtl nckrtl closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant