Skip to content

The turn ledger keys a turn by its own id, so two turns of one mind are two turns - #5737

Merged
joelteply merged 2 commits into
canaryfrom
cormac/turn-ledger-by-turn
Nov 3, 2026
Merged

joelteply merged 2 commits into
canaryfrom
cormac/turn-ledger-by-turn

Conversation

@joelteply

@joelteply joelteply commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fable on #5736 (card 7471b449): IN_FLIGHT and CONFIRMED were sets of persona ids. A mind holding
two turns at once (a fork beside her act) counted once, and the first to end removed the other's
mark: a confirmed turn ending cleared her CONFIRMED entry while the other was still confirmed,
an unconfirmed one ending cleared IN_FLIGHT under a still-running turn. The settle's bound and
awaited() then miscounted while both ran.

  • One map, TURNS: TurnId -> Turn { persona, started_ms, confirmed }. begin_turn issues the id;
    confirm() and Drop touch only their own entry. "Confirmed" is a field of the turn, not a second
    set kept in step with the first.
  • in_flight_turns: one entry per turn, elapsed from that turn's own start (the per-persona start
    lookup and its map_or are gone). confirmed_in_flight counts confirmed turns.
  • turn_in_flight(persona): any turn of hers. in_flight_starts: one row per mind, her longest-running
    turn's start, which is what its one consumer (resident_service::close_windows) asks.
  • Test two_turns_of_one_mind_are_two_turns: two turns of one persona, one confirmed; ending the
    confirmed one leaves the other in flight and the confirmed count back where it started.

Not changed: continuum-engine's slot_work IN_FLIGHT is keyed by persona too; it is a different
map (slot custody), raised on the card rather than folded in here.

continuum card 7471b449

Validation

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

PASS on the code at 06fea13 (Fable), with one test fold-in before merge.

Verified your claim (read the diff at 06fea13, turn_ledger.rs):

  • confirm() does TURNS.lock().get_mut(&self.id) and Drop does TURNS.lock().remove(&self.id), so each touches only its own TurnId. Ids come from a monotonic AtomicU64, so two turns can never share one.
  • in_flight_starts takes the min of started_ms per persona, so each mind's entry is her longest-running turn. The start now comes from the turn itself instead of LAST_TURN_MS, which also removes the old map_or race.
  • git grep IN_FLIGHT\b|CONFIRMED\b at the head: no reader of the old sets remains.

Fold-in (a flake, not the logic): two_turns_of_one_mind_are_two_turns (turn_ledger.rs:229-238) and the existing turn_ingress.rs:304-314 both assert on the process-wide confirmed_in_flight() as before/before + 1. cargo test runs them on parallel threads in one binary, so either test confirming or ending its turn between the other's before read and its assert shifts the count by one. Before this PR only one test did it; now two do. Assert on her own turns instead, e.g. a #[cfg(test)] count filtered to persona (TURNS.lock().values().filter(|t| t.persona == p && t.confirmed).count()), in both tests. Merge on green after that.

joelteply and others added 2 commits November 3, 2026 10:54
…re two turns

Fable on #5736 (card 7471b449): IN_FLIGHT and CONFIRMED were sets of persona ids. A mind holding
two turns at once (a fork beside her act) counted once, and the first to end removed the other's
mark: a confirmed turn ending cleared her CONFIRMED entry while the other was still confirmed,
an unconfirmed one ending cleared IN_FLIGHT under a still-running turn. The settle's bound and
`awaited()` then miscounted while both ran.

- One map, TURNS: TurnId -> Turn { persona, started_ms, confirmed }. begin_turn issues the id;
  confirm() and Drop touch only their own entry. "Confirmed" is a field of the turn, not a second
  set kept in step with the first.
- in_flight_turns: one entry per turn, elapsed from that turn's own start (the per-persona start
  lookup and its map_or are gone). confirmed_in_flight counts confirmed turns.
- turn_in_flight(persona): any turn of hers. in_flight_starts: one row per mind, her longest-running
  turn's start, which is what its one consumer (resident_service::close_windows) asks.
- Test two_turns_of_one_mind_are_two_turns: two turns of one persona, one confirmed; ending the
  confirmed one leaves the other in flight and the confirmed count back where it started.

Not changed: continuum-engine's slot_work IN_FLIGHT is keyed by persona too; it is a different
map (slot custody), raised on the card rather than folded in here.

continuum card 7471b449

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…irmed count (Fable on #5737)

Both two_turns_of_one_mind_are_two_turns and the settle's confirmed-turn test asserted the global
confirmed_in_flight() as before/before+1, which another test thread can move between the reads:
a flake. A test-only confirmed_turns_of(persona) counts hers, and the settle test's any-turn
closure (satisfiable by another thread's turn) becomes the same per-persona check.

continuum card 7471b449

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the cormac/turn-ledger-by-turn branch from 06fea13 to d4a6e84 Compare November 3, 2026 16:56
@joelteply

Copy link
Copy Markdown
Contributor Author

Delta PASS at d4a6e84 (Fable). I read the fold-in commit alone (git show d4a6e8480, 2 files, +14/-11; the rest of the range-diff is the rebase over #5735/#5736). Both tests now count only her own turns through the #[cfg(test)] confirmed_turns_of(persona), and no global before/before + 1 read is left in either. The settle test's any(t.confirmed == ..) closure, which another thread's turn could also satisfy, became the same per-persona check, so that race is gone too. Merge on green.

@joelteply
joelteply merged commit 2baf020 into canary Nov 3, 2026
18 checks passed
@joelteply
joelteply deleted the cormac/turn-ledger-by-turn branch November 3, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant