Skip to content

fix(conn-server): an undone settle keeps the thread's place in Active - #260

Merged
nckrtl merged 16 commits into
mainfrom
conn-server/unsettle-restore-anchor
Nov 24, 2026
Merged

nckrtl merged 16 commits into
mainfrom
conn-server/unsettle-restore-anchor

Conversation

@nckrtl

@nckrtl nckrtl commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

Undoing a settle sends thread.unsettle with restoreUnsettledAt. The Conn Server ignored it, so an undone settle jumped to the top of Active. Gate reviews then found more places where thread commands, their receipts and their events differed from T3's Orchestrator.ts.

Fix (conn-engine, plus the time parser in conn-support)

Thread commands

  • The unsettle anchor is restored as T3 does: a time, null, or a refusal for a bad time.
  • Command times (restoreUnsettledAt, snoozedUntil, visitedAt) parse as T3's DateTime.make: V8's Date.parse, ported in js_date.rs.
  • An archived thread refuses the lifecycle commands first.
  • thread.auto-settle refuses a thread set active or changed after its snapshot, then settles.
  • A settle whose expectedLatestRunId is not the latest run is refused.
  • thread.visit keeps the later visit, reading the stored mark as a command time, and records thread.visit-recorded.
  • Thread setters record their event even when nothing changes, as T3's deciders do.

Projection and envelope

  • The thread's updatedAt follows T3's ProjectionStore.ts; the list of events is generated from T3.
  • The envelope's providerInstanceId is set wherever T3 sets it, including the first message after a merge-back.

Receipts

  • Receipts are kept for good and record refusals.
  • They answer only for their owner, chosen as T3's commandThreadId; a fork's and a merge-back's owner is the target thread.
  • Migration 5 adds owner_kind (thread or project), owner_id and error, and an index on sequence, in one transaction. A receipt from before the upgrade names no owner, so a retry of an old command is refused, never run twice.
  • A project command takes its id inside its write (insert-if-absent; a receipt is never replaced). It records its project and T3's command type (project.update is recorded as project.meta.update).
  • A refusal from project planning is recorded with its typed cause and replayed. Folder and storage failures stay retryable. A replay with no project row is T3's typed read error.
  • A replayed queue.resume or queued-run.start checks the queue again.
  • The queue start uses the run's effective model selection: a message that follows the conversation takes the thread's current one.
  • The queue holds when that provider is off by T3's queue rule: only an explicit project override or a machine entry turns it off. The server reads this from settings under the lock, without copying them.
  • A command that writes nothing answers its own thread's latest sequence.

Proof

Every test below fails on the head before it. They are in conn-engine, apart from the date fixture and the client check.

  • Receipts:
    • a_fork_receipt_belongs_to_its_target_thread
    • receipts_from_before_owners_name_them_or_refuse
    • persists_rejected_command_receipts_across_retries and the duplicate-create retry (T3's tests, ported)
    • an_old_retry_after_an_undo_leaves_the_thread_as_it_is
    • a_replayed_queue_resume_starts_what_waits
    • the_receipt_high_water_reads_an_index
    • the_receipt_upgrade_is_all_or_nothing
    • a_command_id_keeps_its_outcome_across_a_reopen (audit 1.6 and 1.7, moved from fix/conn-server-rejected-receipts): after a reopen, a refused id is refused again though its precondition now holds; an accepted archive replays with its original sequence after an undo and 4,400 later writes; the same command under a new id runs
    • a_v4_store_upgrades_and_refuses_its_old_retries: v4 → final, with a reopen, an old retry refused and an accented message search
    • a_receipt_is_never_replaced
    • a_planned_project_refusal_is_replayed
    • a_project_replay_without_its_row_is_a_read_error
    • the_queue_starts_on_the_effective_selection
    • a_project_write_checks_the_receipt_it_would_reuse
    • a_replayed_resume_holds_a_queue_whose_provider_is_off
  • Lifecycle:
    • auto_settle_rechecks_the_thread_against_its_snapshot
    • a_settle_for_a_stale_run_is_refused
    • a_delayed_visit_keeps_the_later_time
    • a_stale_visit_loses_to_a_mark_in_mains_format
    • a_repin_records_its_event_and_a_quiet_stop_answers_its_thread
    • an_archived_thread_refuses_lifecycle_commands_first
    • thread_commands_move_updated_at_as_t3
  • Envelope:
    • a_turns_events_name_the_provider_instance
    • a_merge_back_first_message_names_its_instance
    • thread-cli-diff.mjs compares every event type's providerInstanceId with the T3 server's. It excuses only the one expired question. On each side, that question must be the one the scenario's asked step reported, with its pending row before its terminal row. It passes locally against the real T3 server.
  • Times:
    • date_input_matches_t3s: T3's own answers for 1,683 strings in five zones.
    • client-check.mjs: a year-10000 anchor decodes with T3's schema.

Checks run locally on 0774de39ea (f0a1db8ea5 adds only the moved test, which passes, with fmt and conn-engine clippy clean): cargo fmt --check, workspace clippy with -D warnings, the workspace library and integration tests (conn-engine: 233 passed), and thread-cli-diff.mjs against a release build. The full tools/check.sh was skipped because free disk was below 60 GB; CI runs it.

47bc8ecc2f fixes three review blockers: unpinned scheduled runs and delegated-completion wakes follow the thread's selection, a create checks its folder before it plans, and a monogram counts graphemes. conn-engine: 234 tests pass; fmt and conn-engine clippy -D warnings are clean.

c4de594204 fixes three more: a settle waits for a queued user message, a queued run's start moves the thread to its selection, and the runner sends a delegated result to the conversation that asked for it. conn-engine: 236 tests pass; conn-mcp, conn-features and conn-server tests pass; fmt and conn-engine clippy -D warnings are clean.

The next commit makes a settle cancel queued automatic runs (scheduled, agent or server), so a later resume never starts them. The same test suites pass.

Not in this PR

  • Engine startup: opening the engine off the runtime thread belongs to feat(conn-server): commit effects with their command in an outbox #261. This PR adds only the receipts(sequence) index.
  • Visit opened: T3 also records palette-search open stats (opens) on a visit; Conn ignores opened.
  • Question at turn end: T3 cancels a pending question when its provider turn ends (dismissNativeUserInputs). Conn expires it at the session release instead. thread-cli-diff excuses only that exact row.
  • Project command reusing a thread receipt's id: this is not refused yet.
  • Resumed monitor notification: it publishes the old provider instance on turn-item.updated before run.updated.
  • Duplicate project id, fresh command id: Conn returns ProjectConflictError or recreates a soft-deleted row; T3 returns ProjectInvalidError.

🤖 Generated with Claude Code

Follow-up (non-blocking, from the round-3 review)

  • Settling cancels queued delegated-completion notifications, but a sibling task from the same parent run that finishes after the settle can still start a new parent turn. The TypeScript server disposes delivery for all sibling tasks during settle (DelegatedCompletionDelivery.test.ts:1959). Settling on main cancelled nothing, so this is not a regression; it moves to a follow-up PR.

…e settle cleared

The engine ignored restoreUnsettledAt, so undoing a settle moved the
thread to the top of Active. It now sets unsettledAt to the given time,
to null for null, and refuses a time that does not parse, as T3's
Orchestrator does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 23, 2026
…tries and wire times

- An archived thread refuses thread.unsettle before its anchor is read.
- The anchor parses as T3's DateTime.make: a time without a zone is UTC.
- A fresh command on a thread already active records thread.unsettled and
  keeps the anchor and updatedAt; a retry of the same command id records
  nothing. The shell row keeps its updatedAt, as T3's projection does.
- The event envelope carries providerInstanceId, from the updated thread.
- Wire times outside years 0000-9999 get toISOString's signed six-digit
  year, so T3's client decoder reads them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size:L and removed size:M labels Nov 23, 2026
… and envelopes

- Command times (restoreUnsettledAt, snoozedUntil, visitedAt) parse as T3's
  DateTime.make: a port of V8's Date.parse, legacy forms included, with
  Effect's zone rule and the server's zone for local times. Checked against
  T3's own answers for 1683 strings in five zones (gen-date-cases.mjs).
- An archived thread refuses settle, auto-settle, unsettle, snooze,
  unsnooze, auto-settle set, pin, unpin and both reorders first, as T3.
- The thread's updatedAt follows T3's ProjectionStore: a thread event writes
  its payload's, every other event its own time, in the row and the stored
  thread (list generated from T3). Pin and settle keep updatedAt as T3 does.
- The event envelope names providerInstanceId wherever T3's does, mapped
  flow by flow; thread-cli-diff compares it with the T3 server.
- Command receipts are kept for good and record refusals: a retry gets the
  recorded refusal, a receipt answers only for its own thread, and an old
  retry after an undo changes nothing (T3's receipt tests, ported).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl and others added 2 commits November 23, 2026 20:04
… and replay follow T3

- Receipts name their owner (owner_kind thread or project, owner_id), chosen
  by command type as T3's commandThreadId: a fork's and a merge-back's is
  the target thread. Migration 5 names older receipts' owners from their own
  events; one nothing proves is kept and refused, never run twice. A project
  receipt never answers for a thread.
- A replayed queue.resume or queued-run.start checks the queue again and
  answers the recorded sequence. A command that writes nothing answers its
  own thread's latest sequence. Thread setters record their event even when
  nothing changes (a re-pin keeps updatedAt).
- thread.auto-settle refuses a thread set active or changed after its
  snapshot, then settles with the archive guard first.
- thread.visit keeps the later visit, compared as times, and records
  thread.visit-recorded.
- The first message after a merge-back names its instance on the handoff and
  transfer events.
- The receipts' high-water mark reads an index. Opening the engine off the
  runtime thread is #261's.
- thread-cli-diff excuses only the expired question after its session's
  release, row by row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
thread.settle with an expectedLatestRunId that is not the thread's latest
run (every run by ordinal, queued ones too; or no run at all) is refused
with T3's "The thread received another run before settlement." instead of
returning quietly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 23, 2026
…ownership and readable search

- A Codex Stop that times out while its root still runs stays pending; the root's later
  end settles the rest of its lineage (T3 forks this wait).
- A close marks the position of the events sent before it, so an interrupted turn the
  provider's own close produces is not taken for a confirmed Stop. The pump reads its
  receiver under a lock it never holds across a store write; a busy pump is counted by
  the close, an idle pump marks the position itself.
- A Stop ends every open node and item in the run's subagent threads whose run is none
  or the root run, and clears `streaming` on each settled item (T3's ownership test).
  The traversal follows every owned thread, with no cap.
- The silent-child watchdog ends a child only on T3's missing thread (-32600,
  `thread not found:`). A child still running after the last check keeps its route.
- Deferred root terminals wait per native root turn, as T3's deferredRootTerminals.
- Readable search moves to schema step 6 (#260 keeps step 5). The upgrade and the T3
  import share one paged pass by message_keys.id, and every write goes through the same
  search-entry writer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d queue admission as T3

- Migration 5 names an older receipt's owner only from its own execution:
  the event at the receipt's sequence must carry its command id, so an older
  run of a reused id (main pruned receipts, not events) never decides it. A
  delegation's parent is the thread whose task row names the created child.
  The upgrade pages receipts and commits columns, owners and the version in
  one transaction.
- The queue start holds the queue when the run's provider is off for its
  project (T3's startNextQueuedRun), so a replayed queue.resume starts
  nothing then.
- A project write reads its receipt in its own transaction and records its
  project and command type: a thread command's id, or another project's or
  command's, is refused with T3's text and the receipt kept.
- thread.visit reads the stored read mark as a command time, so main's
  stored forms compare correctly.
- thread-cli-diff excuses the expired question only when it pairs with
  exactly one T3 question for the same native request, thread, run and
  request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 23, 2026
…ver, and settlement reads what T3 reads

Compaction timers outlived archive, delete and shutdown; a pending guest message
did not keep a thread from settling; an idle compaction could swallow a delegated
result not yet delivered; and every completed turn read the thread's full history.

- Archive and delete cancel the thread's timer. Shutdown refuses new timers,
  then the server aborts and joins the settlement loop and the timers before the
  engine stops. A timer is registered under the lock its task removes it with.
- The engine counts a thread's pending guest messages (guestShare.messages).
- The /compact admission is a no-op while a finished task's result waits for its
  wake message, in the same transaction as the run check.
- A timer reads the thread record first, then only the records the window needs.
- Each settlement decides on settings and time read right before its dispatch.
- The startup sweep starts after the MCP service, and a settlement wakes the
  sweep after its terminal cleanup.
- The auto-settle recheck takes #260's shape; on rebase onto #260 its version
  stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 23, 2026
#311 carried its own copy of the auto-settle snapshot-and-override recheck. Next
to #260's, that was a second check. The thread_settle conflict resolves to #260's
block alone, under `thread.auto-settle`, with its archived and latest-run
refusals. A manual settle with a matching `expectedLatestRunId` and no
`snapshotAt` settles (#260's `a_settle_for_a_stale_run_is_refused`). #311's sweep
only passes the shell's `updatedAt` as `snapshotAt`, which #260 keeps equal to the
stored `updatedAt`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl and others added 2 commits November 23, 2026 22:32
… queue start as T3

- Migration 5 only adds the receipt columns (one transaction). A receipt from
  before keeps no owner, so a retry across the upgrade is refused, never run
  twice. The evidence-based backfill and its tests are gone.
- A project command takes its id inside its write (insert-if-absent) and
  validates a receipt another write holds there; a receipt is never
  replaced. A refusal from planning is recorded under the project and T3's
  command type (project.update is project.meta.update) and replayed; folder
  and store failures stay retryable. A replay with no project row is T3's
  typed read error.
- The queue start resolves the run's effective selection (a message that
  follows the conversation takes the thread's) and checks it with T3's queue
  rule: only an explicit project override or a machine entry disables. The
  server reads it from the settings under the lock, without a copy.
- thread-cli-diff binds its one exception to the thread and run of the
  scenario's asked step, with the pending row before its terminal row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moved from fix/conn-server-rejected-receipts (4bbd2ac, audit 1.6 and
1.7): after the store reopens, a refused id is refused again though its
precondition now holds, an accepted archive replays with its original
sequence after an undo and 4,400 later writes, and the same command under a
new id runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 23, 2026
…one transaction

A launch wrote the new thread and its first message as two commands, so a
dropped socket between them left an empty thread. The gates then found
replays and claims that could land on the wrong thread, project or
checkout, or leave state behind. Each check now runs in the write that
commits, as T3's orchestrator does.

- thread.create carries its first message; thread, message and run commit
  together. A reused thread takes its message in a command of its own.
  Every separate first message checks the checkout its claim recorded,
  read from the claim's own event.
- A launch's own checks (reusable thread, project, checkout, mode limit)
  run at admission in the command's write. As in T3's ThreadLaunchService
  they record no receipt, so a refused launch id stays usable.
- Receipts (#260's owner columns) decide replays. A replayed launch must be
  the id's own thread.create; only an accepted message.dispatch of the
  thread with its run counts as a first message.
- A launch runs on a server-owned task. Shutdown refuses new launches,
  cancels worktree setup through the host, and gives admitted launches a
  10 s grace to commit or clean up in process, as T3 closes its
  preparation scope. A worktree a crash leaves stays on disk, as in T3.
- conn-vcs reports a worktree's claim before `git worktree add` and runs
  git in its own process group, so a cancel during `post-checkout` reaps
  the hook's process tree and removes the checkout and its branch. A
  discard removes the branch only once the worktree is gone, and says what
  stayed.
- Provider admission passes a launch already accepted and reads settings
  off the runtime thread; a thread.create with its first message checks
  the provider in its commit.
- The returned projection must be in the launch's project.
- thread.delete honours onlyIfUnused under the thread lock.
- A refused or replayed message releases only its own claim's copies.
- The .gitmodules check runs off the runtime thread.
- Test binaries stop git's repository search at the temp folder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y, monograms count graphemes

- An unpinned scheduled dispatch sets followsThreadSelection, and the queue
  start recognises Conn's delegated-completion wakes by their id, so both run
  on the thread's current selection, as T3's followsCurrentConversation.
- project.create checks the folder before it plans, as T3's
  ProjectService.create: an offline folder another project holds is a
  retryable ProjectOperationError, not a recorded conflict.
- A monogram counts extended grapheme clusters, as T3's Intl.Segmenter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl and others added 2 commits November 23, 2026 23:56
… the thread, wakes reach their conversation

- thread.settle refuses a thread with a queued user message, as T3's
  settle; queued server, agent or scheduled messages do not block it.
- Starting a queued run on another selection moves the thread to it in the
  same transaction, as T3's startNextQueuedRun, so an unpinned scheduled run
  queued behind it starts on the same model.
- The runner recognises delegated-completion wakes with the queue's
  is_delegated_completion, so a fresh scheduled run's result reaches the
  conversation that delegated it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A settle refused a queued user message but left a queued scheduled, agent or
server run in place, so a later queue resume still started it. The settle
now cancels those runs before it writes thread.settled, as T3's settle
cancels its automatic cohort.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…data matches ICU

Linux tzdata merges backzone local mean times (Amsterdam reads Brussels), so pre-1970 cases
differ from the TypeScript server's ICU values on the CI runner, not in this code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl and others added 4 commits November 24, 2026 01:43
# Conflicts:
#	apps/conn-server/crates/conn-engine/src/lib.rs
# Conflicts:
#	apps/conn-server/crates/conn-engine/src/runner.rs
#	apps/conn-server/crates/conn-engine/src/store.rs
@nckrtl
nckrtl merged commit e18dbf7 into main Nov 24, 2026
48 checks passed
nckrtl added a commit that referenced this pull request Nov 24, 2026
…ent-folded message search, as T3 (#285)

* fix(conn-server): agent thread search finds a thread by its linked PR, as T3

conn_thread_search matched title, branch and project only, so an agent given
#7483, example/fixture#7483 or the PR URL could not find the active thread
that owns the PR. The candidate filter now reads the thread's visible PRs as
threadSearchPullRequests does: the number after a pr/pull/# prefix, the
newest three titles, and owner/repo#N, the URL and the thread id by
matchReference's whole-query rule. Dismissed stack members stay out.

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

* fix(conn-server): message search folds case and accents, old indexes too, as T3

A search for "ecole fermee" or "fermée éc" missed a message that reads
"École fermée à Lyon": the trigram index and the short-word check folded
ASCII case only. The index now stores text folded as T3's foldCharacter does
(NFKD, marks dropped, lower case), queries fold the same way, and the
short-word check reads the folded index text. Snippets still show the
original text. An existing index is refolded once, in batches inside one
transaction, under a meta mark rather than a schema version (PR #260 also
adds version 5). A T3 import folds what it indexes.

New dependency: unicode-normalization 0.1.26 (unicode-rs, MIT/Apache-2.0
and Unicode-3.0, both allowed), with tinyvec. Measured cost: +113 KiB in a
stripped LTO release binary, static tables only, no heap.

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

* fix(conn-server): search folds as T3's index and query, and reports the refold

Gate findings 9.4 and 9.5 on #285.

- conn-mcp: the query folds as `foldSearchQuery` (wrapping quotes, NFC, case and
  accents), and so do titles, branches and projects. A PR's `#N` and searched
  title match word by word at word starts (`matchToken`), so "resume" finds
  "Résumé indexing" and a quoted "example/fixture#7483" finds its thread.
- conn-engine: the index folds as SQLite's `trigram remove_diacritics 1`, now the
  public `conn_engine::fold`: Latin diacritics go, but dakuten, Hangul and other
  letters stay apart. Queries are NFC first. The `message_search_folded` mark is
  2, so a store folded by the first fold is folded again once, from message text.
- conn-engine: a query word shorter than four characters must start a word in the
  message (`messageMatcher`), so "marker me" no longer finds "marker fermé".
- conn-engine: the refold prints T3's migration lines (start, every 10,000
  messages, finished), now generated into conn-contract from
  `databaseMigrationLog.ts`, so the desktop keeps waiting past its readiness limit.

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

* fix(conn-server): search matches T3's fold, matcher and project hints

Round-2 gate findings on pass 9 search:

- conn_thread_search matched a project name and a PR only as one
  substring, so "lakebed #7483" missed a thread of project Lakebed linked
  to #7483. It now matches word by word across title, PR number and
  titles, branch and project, as scoreThreadSearch, and keeps matchHint's
  rule that a field explains the words left after the project's name.
- The index fold used Rust's Unicode tables and differed from SQLite on
  461 code points (it took both marks off "ǡ", and kept "ſ"). It now reads
  a table generated from the bundled SQLite's trigram tokenizer
  (sqlite-fold.txt); a test fails when SQLite folds differently. The fold
  mark goes to 3, so stores at 2 refold.
- The matcher ports findMessageToken: word length counts before the
  index fold ("İce" finds "service"), hits inside a hex id do not count,
  and the snippet starts at the accepted occurrence.
- A refold batch ends at 4 MiB of text or 500 rows, read in rowid order
  without a sort.

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

* fix(conn-server): search reads words, offsets and spellings as T3's matcher

Round 3 of the gate on pass 9 (audit 9.4, 9.5):

- Message queries are lowercased before the index fold, as messageSearchTokens:
  uppercase Georgian finds lowercase, though SQLite's fold leaves Mtavruli alone.
- Words follow T3's general categories (\p{L}, \p{N}, \p{Ll}, \p{Lu}, \p{So}, from
  regex-syntax, already in the binary): a symbol starts a word only where a letter
  would, in fields and in messages. Messages read in UTF-16 units, so an emoji above
  U+FFFF still brings its own boundary, as in T3.
- messageMatcher's snippet offset: the lowercase pass first, the accent-folded pass
  only without a whole word; words side by side as typed first, then the shortest
  stretch, all in UTF-16 units; the snippet reads the offset back.
- A refold batch never passes its byte budget: a row that would is read again as
  the next batch's first, and a row larger than the budget is folded alone.

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

* fix(conn-server): search snippets cut as T3's buildSearchSnippet

The snippet started 80 characters before the match. It now follows
buildSearchSnippet in ThreadSearch.ts, in UTF-16 units: from the next word start
within 24 units before the match, never inside a surrogate pair, emphasis and code
marks dropped, whitespace collapsed, at most 240 units with ellipses where the text
was cut.

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

* fix(conn-server): agent search ranks title hits before the limit, as T3

A thread titled as the query dropped out under a small limit when a newer
thread only linked a PR of that title. Hits now rank whole title, then
title, then other fields, before the limit; recency breaks ties.

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

* fix(conn-server): message search reads a Markdown link as its label, as T3

The matcher saw the link address, so 'quartz' found a message that only
shows 'release notes'. Links reduce to their label before matching and the
snippet, like ThreadSearch.ts's MARKDOWN_LINK.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 24, 2026
The branch carried #260's commits up to a6fe0c2. The merge used main at
9017c1b plus that copy of #260 as its base, so only #311's own changes met
main's. Settled-thread cleanup keeps main's serialized task, and the settlement
sweep wakes after it, even when the settlement is no longer current.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl added a commit that referenced this pull request Nov 24, 2026
…che expires, as T3 (#311)

* feat(conn-server): settle idle threads and compact before Claude's cache expires, as T3

Remediation entries 2.8 and 2.9: the settings and commands existed, but nothing
issued them.

Automatic settlement (conn-server settlement.rs, T3 ThreadSettlementService):
a sweep at start, every minute, after a settings change and after a
settlement. Candidates come from a new engine read ported from
getSettlementCandidates; each decision ports resolveAutoSettlementAt with the
project's settings and sends thread.auto-settle with the thread's updatedAt
as snapshot. The engine now refuses an auto-settle for a thread changed since
(Orchestrator.ts:15119). Settling on a branch lookup's pull request on the
host is not built.

Idle compaction (conn-server idle_compaction.rs, T3 IdleCompactionService and
idleCompactionWindow): a completed Claude run in beforeCacheExpires mode
starts a per-thread timer that sends /compact two minutes before the prompt
cache expires, rechecking everything at the deadline. message.dispatch takes
idleCompaction (a no-op while busy, Orchestrator.ts:7027), and the shell and
the settlement candidates leave compaction runs and messages out
(isSilentRunForShell, isIdleCompactionMessage).

Defaults and the compaction text and threshold are generated from T3
(gen-upstream.mjs).

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

* fix(conn-server): compaction timers end with their thread and the server, and settlement reads what T3 reads

Compaction timers outlived archive, delete and shutdown; a pending guest message
did not keep a thread from settling; an idle compaction could swallow a delegated
result not yet delivered; and every completed turn read the thread's full history.

- Archive and delete cancel the thread's timer. Shutdown refuses new timers,
  then the server aborts and joins the settlement loop and the timers before the
  engine stops. A timer is registered under the lock its task removes it with.
- The engine counts a thread's pending guest messages (guestShare.messages).
- The /compact admission is a no-op while a finished task's result waits for its
  wake message, in the same transaction as the run check.
- A timer reads the thread record first, then only the records the window needs.
- Each settlement decides on settings and time read right before its dispatch.
- The startup sweep starts after the MCP service, and a settlement wakes the
  sweep after its terminal cleanup.
- The auto-settle recheck takes #260's shape; on rebase onto #260 its version
  stays.

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

* fix(conn-server): sidebar times skip idle compactions; fractional auto-settle days, as T3

The thread shell counted the server's own /compact as the user's latest
message. After an idle compaction, latestUserMessageAt moved to the compaction
and latestUserAuthoredMessageAt became null. T3's buildThreadShell leaves
idle compactions out of both (idleCompactionOf), and takes the latest
user-authored message on its own.

sidebarAutoSettleAfterDays is a number from 1 to 90, so 1.5 is valid. The
sweep read it with as_u64, so a fractional count never settled anything. It
is now an f64 and compared as T3 does.

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

* fix(conn-server): a pull request watch does not stop idle compaction, as T3

The timer read the thread shell's pendingBackgroundTasks, which include the
thread's pull request watches. With a watch as its only task, an eligible
Claude thread never compacted. T3's idleCompactionWindow passes no links to
derivePendingBackgroundWork (IdleCompaction.ts:75), so watches do not count.
The timer now leaves them out.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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