Skip to content

fix: a resolved peer is one you can actually reach (lets-cbmg7) - #185

Merged
restarter merged 17 commits into
mainfrom
lets-cbmg7-let-lets-hub-address-any-live-session-of-another-p
Sep 20, 2026
Merged

restarter merged 17 commits into
mainfrom
lets-cbmg7-let-lets-hub-address-any-live-session-of-another-p

Conversation

@restarter

Copy link
Copy Markdown
Owner

Summary

The eight-item peer-transport hotfix batch from the owner's scope decision on lets-cbmg7, as one PR. Every item is the same shape of bug: the two sides of the peer lane disagreed, or a failure was invisible to everyone who did not read the envelope.

The headline change is a root-cause one. lets peers orchestrator built its target from role files plus the machine-wide Claude registry and never asked whether this repo can reach it, while Peer.Send is computed only in who/peers(). The field therefore came back as "" on every resolution - "not computed", which three separate bug reports read as "unreachable". Resolution now looks the target up in the same rc.peers(ctx) set the send path uses, and refuses by name instead of handing back a target the sender cannot reach.

What changed

  • Resolution answers "can I send to this?" - a target only when this repo's peers() can reach it; otherwise refused[{name, scope, session6, reason, detail, hint}] with target_in_other_repo | target_not_alive | target_unsendable. send is emitted only where it is computed. An orchestrator of unknown liveness keeps the resolution ambiguous rather than letting the only visible one win silently.
  • Resolution never answers on an exhausted context - the branch is read before the 2500 ms budget starts, and a spent budget degrades loudly (branch_unreadable / budget_exhausted) instead of looking "unbound" and re-routing to a different orchestrator. repoWorktrees no longer swallows a failed git worktree list, which is what made a sibling worktree's session look like another repo.
  • A non-delivery is as loud as a delivery - tell exits 11 while ok stays true, keeps its handoff when nothing was typed, and names the retry with the SAME msgid (carrying --repo-index / --repo when the target was resolved elsewhere). Once typing started the handoff is consumed and nothing is ever resent. Self-send is refused once, at frame; abandoned handoffs are pruned after 24h.
  • tail stops hiding what it cut - 16 KB per turn for a reply (--since-message) or a message addressed to the reader, 2 KB otherwise, a 64 KB per-call ceiling, and truncated_bytes counting source bytes at both levels. omitted: 0 next to a cut answer was the actual bug.
  • ScreenTail redacts URL credentials (redact.Creds), which the rest of the pipeline already stripped.
  • The orc skill says what happened - the Args line agrees with the verb table on tell, a refusal and a non-delivery each get a mandatory line that survives footer=none, and a non-completion is no longer reported as "no orchestrator is alive".

Open question for the owner - deliberately not settled here

Should cross-repo messaging work on the terminal launcher at all? repo_index is produced only by who --orca-repos, whose repo list comes from Orca's registry, and its only caller /lets:hub refuses without LETS_LAUNCHER=orca. Answering "yes" needs a repo-identity source independent of Orca - a separate, larger change, together with this task's two original hub items (listing non-orchestrators, and de-duplicating nested repos). This PR makes the failure honest and actionable; it does not make cross-repo work.

Review trail

Six defects were found after the first pass and fixed in the later commits: two by a branch-level self-check, four by an external Antigravity review run against a hand-off brief. Both of that review's MAJOR findings were defects in the instructions given to the implementer, not in the implementation - a budget guard that only covered an unreadable branch, and a byte counter that double-counted redact.Cap's own marker. Every finding carries a regression test.

go build, go vet, go test -count=1 ./... (27 packages) and golangci-lint are clean.

Task

lets-cbmg7: Let /lets:hub address any live session of another project, and list nested repos once (stays open - the deferred items above are still its scope)

🤖 Generated with Claude Code

restarter and others added 17 commits September 19, 2026 22:51
readHandoff no longer deletes the handoff itself; Tell and AskRO now
consume it only once something was typed or the handoff is proven
unusable, so an untyped tell can retry with the same msgid. Frame
refuses a session addressing itself and prunes handoffs older than 24h.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
cli/internal/cli/peers.go already printed the envelope before returning
the typed error, so this task adds the coverage that pins the contract:
a kept handoff, a same-msgid retry, and delivered/claude routes that
consume the file and return no error.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
An addressed message or a relayed reply now keeps up to 16 KiB instead
of 2 KiB, a whole tail call stays under a 64 KiB ceiling, and every
byte either cut trims into is counted in truncated_bytes - omitted: 0
can no longer sit next to a cut answer.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Moving the addressable() check ahead of the liveness check had made
`unknown` unreachable: an Unknown-liveness role file is always
Send=none in peers(), so it was refused before ever being counted,
and one addressable candidate silently outranked one this repo
cannot vouch for. Count liveness before asking addressability.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
"Nothing was typed. Retry with the same msgid" was printed for every
non-delivery, including a send that was attempted but never proved -
where the handoff is already consumed and a retry would risk a
duplicate. The NOT DELIVERED guidance and cli/README.md now branch on
the envelope's `note`, which is only ever set when nothing was typed.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
The kept-handoff Note pointed at "lets peers tell --to-session ...
--msgid ..." even when the target was looked up with --repo-index or
--repo (the hub's cross-repo path), so following the hint would look
the target up in the caller's own repo and fail peer_unreachable.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Orchestrator()'s 2500ms budget could be spent before binding.go read
the branch: exec.CommandContext fails instantly on an expired ctx, an
unreadable branch looks unbound, and the unbound path can silently
pick a DIFFERENT live orchestrator than the one this branch is bound
to. ResolveOptions now takes an optional Branch read ahead of the
budget; when it is still empty AND the ctx is already done, resolution
degrades loudly (branch_unreadable) instead of falling through.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
A turn the call ceiling dropped contributed only its kept text's
length to truncated_bytes, silently forgetting bytes that same turn
had already lost to the per-turn cap - a 40 KiB turn capped to 16 KiB
then dropped reported ~16 KiB lost instead of ~40 KiB.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
D, the root cause: repoWorktrees swallowed a failed `git worktree
list` and silently fell back to [mainRoot], so every session in a
linked worktree dropped out of the peer set and addressable()
misdiagnosed it as target_in_other_repo. It now returns the failure
as a Degraded entry too; registryPeers carries it through and hands
its caller the already-resolved roots instead of a second identical
subprocess call.

C: the budget guard only fired when the branch itself came back
empty, so an unbound caller on a perfectly readable branch got no
guard at all - if D had already narrowed the peer set, an orchestrator
in the main checkout could still be silently picked as `single`. The
guard now fires on any ctx.Err() != nil after the binding lookup,
using budget_exhausted when the branch was readable.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
A ceiling-dropped turn's len(Text) already includes redact.Cap's own
" ...[truncated N bytes]" marker once that turn was also per-turn
capped, so adding TruncatedBytes on top double-counted the cut by the
marker's length (~27 bytes per affected turn) - an overcount, not a
user-visible break. Turn now carries the pre-cap source length
unexported (no JSON change); tail.go sums that instead.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
state is empty whenever Tell had no peer at all (peer_unreachable
with no target), so the template printed a literal "()" if followed
verbatim.

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
source=none with reason=budget_exhausted or branch_unreadable means
resolution never finished, not that no orchestrator is alive - it
carries no refused[] entry, only a Degraded{git|context, ...}. The orc
skill, the start.md pointer and the README now say so; the README
also lists the two new degraded reasons (worktrees_unreadable,
deadline_exceeded), and Degraded.Source's comment now names git and
context (plus the pre-existing repo, also missing from it).

Task: lets-cbmg7
Co-Authored-By: Claude Sonnet 5 <[email protected]>
@restarter
restarter merged commit 8846a70 into main Sep 20, 2026
3 checks passed
@restarter
restarter deleted the lets-cbmg7-let-lets-hub-address-any-live-session-of-another-p branch September 20, 2026 10:19
restarter added a commit that referenced this pull request Sep 22, 2026
#186)

## Summary

A worker session could finish or vanish leaving no record, and nothing
noticed: lets-g5wuz and lets-cbmg7 shipped (#184, #185) and their
sessions left no snapshot, no `released-` marker, nothing that surfaced
them. The same session model (stable session id, changing pid and
terminal) also broke on resume: `lets peers tell` to an orchestrator
resumed with `claude -r` failed `peer_unreachable` while `lets peers
orchestrator` reported it alive.

### Why the archive hook never fired

Orca never archived those two worktrees. gh 2.101.0 (installed
2026-09-15) includes cli/cli#14007 (gh >= 2.99): `gh pr merge
--delete-branch`, run from another checkout, removes the head branch's
linked worktree itself. Orca's trace (`~/Library/Application
Support/orca/logs/main.trace.ndjson.1`) has no `worktree.remove` /
`archive_hook` span for either; each worktree vanished one second after
its merge (#185 10:19:39Z -> cbmg7 PTYs killed 10:19:40Z; #184 10:33:15Z
-> g5wuz 10:33:16Z), while every Orca "Delete" in this repo ran the
hook, second-exact with its marker. Their task-state files are still in
`.lets/sessions/` - `release` never ran. `/lets:done`'s own merge is not
this path: gh never removes the current or main worktree.

### What changes

- **Session record.** A snapshot records the full HEAD it covers (`-
head: <sha>`, 40 or 64 hex); `/lets:done` writes one before its final
gate, whatever is picked.
- **`lets worktree record --task <id>... [--ref]`.** Per task: `present`
/ `stale` / `missing` by git ancestry (never by time; legacy
`-snapshot-precompact` files still read), the local traces (task-state
files, `refs/heads/` branches), live worktrees, the marker, and
`orphan`. An incomplete inventory fails instead of answering
`orphan=false`.
- **`/lets:start --main`** offers orphans (in progress, a local trace,
no worktree, no marker) in Reopen next to archived claims.
- **`release`** writes its marker (now with `snapshot=`) first, then
compare-and-deletes the task-state file under its lock
(`taskstate.RemoveIfTask`) - a file that changed meanwhile, an
unreadable one or an invalid id is kept, with the reason in
`released.task_state_kept`. A missing record, a failed marker or a kept
file prints a `lets:` line on stderr (even with `--quiet`) and fires
`lets notify`.
- **taskstate** temps moved to `.tasktmp-*`: `.task-<slug>.<digits>.tmp`
is also the state file of a legal branch (`feature.12345.tmp`), which
`Remove` used to delete as a stranded temp.
- **Rule** (lets-rules `## Worktrees`): a worker's PR merged from
another checkout goes without `--delete-branch`, only after `record`
shows `present`; archive in Orca afterwards.
- **Resumed sessions** (peerscmd): one peer per session id - two live
pids, counted machine-wide, are `session_duplicated`; a binding resolves
to the live holder of the name, else the one role file registered under
it (`bound_ambiguous` on a tie); `tell` reports why it cannot reach
(`state`); `lets peers tail <name>`.

### Review

The plan went through three Codex review rounds and the branch through
two; every finding was checked against the code, the confirmed ones are
folded in, and the two answered differently are argued in the plan's Key
Decisions. `TestResume_NewPidNewName` is intentionally RED at eaf120f
(it reproduces the renamed-resume mismatch) and green from 942d519.

## Test plan

- [x] `make test` (race) - green
- [x] `make lint` - 0 issues
- [x] `cd cli && GOOS=windows go vet ./internal/cli/` - clean
- [x] `./cli/lets worktree record --task lets-cbmg7 --task lets-g5wuz
--json` - both show their surviving task-state trace, no worktree, no
marker, `record=missing`, `orphan=true` (the vanished state, now
visible)
- [ ] Owner smoke, resume: bind a worker to a throwaway orchestrator
(`claude --model opus`, `/rename SMOKE-ORC`, `/lets:start --main`),
`/lets:orc ping hi` from the worker; close the orchestrator tab, `claude
-r <sid>` in a new Orca pane, ping again - expect delivery via the
claude route, or a named refusal at resolution (`session_duplicated`
when the old process still runs, `target_in_other_repo` when resumed
from another directory), never `alive` then `peer_unreachable`
- [ ] Owner smoke, archive: in a throwaway Orca worktree with a claimed
task and no snapshot, press Delete - expect the stderr/notify alarm and
a marker ending `|snapshot=missing`

## Task

lets-11zwo: A worker session can vanish leaving no record, and nothing
notices

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@restarter restarter mentioned this pull request Sep 23, 2026
restarter added a commit that referenced this pull request Sep 23, 2026
Version bump for v0.9.2. `make bump VERSION=0.9.2` edited the
version-source files plus the two shipped tracker adapters, renamed
`[Unreleased]` to `[0.9.2]`, and committed only after `make test`, `make
build` and `verify-versions` passed.

**Rebuilt.** The first cut of this branch was taken at `58e2441`, before
lets-f8x54 landed. Rather than let that fix fall under a fresh empty
`[Unreleased]` and miss the release, the branch was recreated from main
at `514afff` and the bump re-run, then force-pushed. The 0.9.2 section
now carries all 15 entries of this round.

What ships: `--fix` across check / review / handoff (#189), the
implementers run mode and `/lets:execute` picker change (#187), handing
an approved plan to an agent tab (#184), `lets worktree record` and the
vanished-worker fix (#186), the peers reachability batch (#185),
`/lets:orc --yes` (#183), the language-rule split (#188), and a peer
role that survives a changed session id (#191).

Known defects shipping with this release, stated deliberately rather
than discovered later: `/lets:done` still creates a duplicate PR when
one is already open (lets-0g49b); the session boundary still breaks on a
branch reused after its PR merged (lets-2t5ns); worktree provisioning
correctness (lets-41cpf) and parallel implementers (lets-7dwc1) are
unfinished. None is new, and none is made worse here.

After merge: `make release-tag VERSION=0.9.2`, then curated release
notes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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