Skip to content

store: exchanges a backfill sends count as turns and keep the session backfilled - #259

Open
connorburgess wants to merge 4 commits into
spacesheep-dev:mainfrom
connorburgess:fix/backfill-transcript-turns
Open

connorburgess wants to merge 4 commits into
spacesheep-dev:mainfrom
connorburgess:fix/backfill-transcript-turns

Conversation

@connorburgess

@connorburgess connorburgess commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Updated against v0.8.19 / main e8bfe999 on 2026-12-05. Current validation and refresh details.

What

A session that sessionpipe backfill sent now reads as core 0.19 sends it. Its card shows how many turns it had, the session keeps its backfilled mark, and its time span is the one the backfill gave. Before this, such a session showed no turns, lost the mark, and its last time moved to its newest exchange, or to the moment it arrived when the exchanges had no time of their own.

Why

Core main (sessionpipe 0.19, packages/cli/src/cli.ts backfillTurns) sends a backfilled session's exchanges as turn.transcript events. Each carries harness.event: "backfill", its ordinal in data.turn, and its own time. They follow a session.backfill that then has no turns. spec/PROTOCOL.md §4 says so: "turns is absent when the sender sends the session's exchanges as turn.transcript (a receiver counts those, and would count them twice)". Core's conformance fixture conformance/delivery/35-backfill-transcript.json sends this shape.

server/store/readings.ts counted turns only on turn.started and on a backfill's turns. It also treated any other event on a session that was not live yet as the session's first live event. So the first exchange set live, cleared backfilled, and moved startedAt/lastAt, and no exchange was ever counted. With no turns counted, nothingHappened() in shared/api.ts was true for the session.

The change, in applyEvent: a turn.transcript marked "backfill" on a session that so far has had only a backfill is history.

  • It keeps the session backfilled, with the backfill's span.
  • The turn count becomes the highest ordinal read plus one, so each turn counts once in all of these cases:
    • a backfill that carries turns (0.17 senders)
    • an exchange sent twice
    • a later sessionpipe backfill run that continues from its cursor (core numbers from transcript_turns)
  • A later run sends no session.backfill, so an exchange's own data.at widens the span. An exchange without a readable time leaves the span alone.

Two cases read as they do today:

  • A live session: its transcripts are not turns, turn.started counts them.
  • A session whose first event this receiver reads is such a transcript, with no backfill before it.

Boot, rebuild and ingest all go through applyEvent, so a restart reads the same. The mock world (web/src/mock/world.ts) also counts a backfill's exchanges as turns.

An entry is now included under Unreleased in CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.

Original proof (before the v0.8.18 refresh)

New test in server/store/store.test.ts, "counts a backfill's exchanges as its turns and keeps it backfilled, after a restart too". It starts with a session.backfill (09:00–09:20, no turns) followed by two exchanges stamped 09:00 and 09:15, and checks:

  • 2 turns, backfilled: true, state done, span 09:00–09:20
  • an exchange sent twice, one with no time and one with a time that does not parse: still 3 turns, span unchanged
  • a later exchange at 10:05: 4 turns, lastAt 10:05
  • the same after closing and reopening the Store
  • a backfill with turns: 5 keeps 5
  • a resumed live session is no longer backfilled and counts no transcript
  • a backfill transcript read first keeps today's reading

On origin/main (4ab6eae) it fails:

 FAIL  server/store/store.test.ts > readings > counts a backfill's exchanges as its turns and keeps it backfilled, after a restart too
AssertionError: expected { key: 'claude-code:old-one', …(21) } to match object { state: 'done', …(3) }
- Expected
+ Received
  {
-   "backfilled": true,
-   "lastAt": "2026-10-01T09:20:00.000Z",
+   "backfilled": false,
+   "lastAt": "2026-10-01T09:15:00.000Z",
    "startedAt": "2026-10-01T09:00:00.000Z",
    "state": "done",
  }

On this branch it passes:

 Test Files  1 passed (1)
      Tests  1 passed | 68 skipped (69)

Checks:

  • npm run typecheck: passes.

  • npm run lint: passes. Its 135 warnings were already on main; the changed lines add none.

  • npm test: 3361 passed, 2 skipped, 1 failed. The one failure is the same timeout on unmodified origin/main (4ab6eae), where the full run gives 3360 passed, 2 skipped, 1 failed. Both runs show:

     FAIL  server/control/remote.parity.test.ts > the receiver's wiring and a page's, through one script > machines, sends, refusals, jobs, a restart, a revoked key, a disconnect and another account: row for row
    TestTimeoutError: Test timed out in 15000ms.
    

    Run alone, that file passes on main (11 passed).

Checklist

  • Every commit is signed off (git commit -s): the DCO is the only paperwork.
  • npm run typecheck && npm run lint && npm test pass; npm run test:e2e for a UI change. (Not a UI change: e2e not run.)
  • New source files start with // SPDX-License-Identifier: Apache-2.0. (No new files.)
  • No secret, real address, hostname or home path in code, fixtures or screenshots (screenshots come from --demo).
  • A change to shared/* names the wire-contract change in the description. (No shared/* change.)
  • A line under Unreleased in CHANGELOG.md.

… backfilled

Symptom: a session that `sessionpipe backfill` (core 0.19) sent reads on its card
with no turns, loses its backfilled mark, and its last time moves to the newest
exchange's (or to the moment it arrived, when the exchanges carry no time of their
own). nothingHappened() (shared/api.ts) then reads it as a session nothing
happened in.

Cause: core now sends a backfilled session's exchanges as turn.transcript events
(harness.event "backfill") after a session.backfill that carries no `turns`
(PROTOCOL.md §4, conformance/delivery/35-backfill-transcript.json). The receiver
counted turns only on turn.started and on a backfill's `turns`, and took any other
event on a session that was not yet live as its first live one.

Fix: a turn.transcript marked "backfill" on a session that so far had only a
backfill is history: it keeps the session backfilled with the backfill's span, and
the session has as many turns as the highest exchange ordinal read plus one, so a
backfill's own `turns`, an exchange sent twice and a later backfill that goes on
from the last one count each turn once. Such a later backfill sends no
session.backfill again, so an exchange's own time (`data.at`) widens the span; one
with no readable time leaves it. A live session, and a session whose first event
this receiver reads is such a transcript, read as before. The mock world counts a
backfill's exchanges as its turns too.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@graphide-review

Copy link
Copy Markdown
Contributor

Open in GraphideGraphide review

TL;DR

  • Sessions loaded by the backfill command will now show their real turn count, keep their "backfilled" mark and keep the time span the backfill gave them. Today they show no turns and look like live sessions.
  • The review found no problems and rates its confidence in this change at the top of its scale, 5 of 5.
  • Ship: the review's verdict is merge.

Merge  nothing found that needs a look first

Core 0.19's sessionpipe backfill sends a session's history as a session.backfill with no turns, followed by one turn.transcript per exchange (marked harness.event: "backfill", with an ordinal in data.turn and a time in data.at). Before this change the receiver read the first such exchange as a live event: it cleared backfilled, moved the span and counted no turns. applyEvent now handles these exchanges on a session that has so far had only a backfill. The turn count becomes the highest ordinal read plus one. A readable data.at only widens the span. The session stays backfilled. The mock world counts the turns the same way, and a store test covers ingest, duplicates, an unreadable time, a restart, a backfill that carries turns, a resume and a transcript read first.

No findings sure enough to post from reading the change.

Merge confidence 5 of 5

Where to read first
  1. server/store/readings.ts:662 - first and rec.live, which pick the branch an event takes
  2. server/store/readings.ts:667 - the existing session.backfill branch, which sets the span and turns that the new branch builds on
  3. server/store/readings.ts:680 - the new backfill-transcript branch: turn count from the ordinal, span widened from data.at
  4. server/store/readings.ts:887 - the turn.transcript case that still runs for these events (last ask/answer)
  5. server/store/core.ts:164 - boot, ingest and rebuild order, all through applyEvent
  6. web/src/mock/world.ts:552 - the mock's matching turn count for backfill exchanges
Tests and reach

Reach: no graph yet, so this review could not trace what the change reaches.

Stages: 288 s
Stage State Seconds
diff done 0.0
reach skipped 100.5
risks skipped 0.0
ci skipped 0.0
find done 145.3
agent skipped 0.0
slop skipped 0.0
scenarios skipped 0.0
verify done 42.0
prove skipped 0.0
score done 0.0

Reviewed 7cdbdb2 in 288 s · graph check: no graph yet, so this review ran without it · Full report · For agents: gr review findings spacesheep-dev/sessionpipe-gui 259

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

Copy link
Copy Markdown
Contributor Author

The backfilled transcript turn-count fix still applies to SessionPipe GUI v0.8.18. Merged current main (d16a2c01) into this branch; the refreshed head is 478687e6. The affected files have not changed upstream, and the original change is preserved.

Added the previously deferred Unreleased changelog entry.

Validation on this head, macOS / Node 22.23.2:

  • npm run typecheck, npm run lint, and npm run build passed. Lint has the same 135 warnings and one informational diagnostic as current main, with no errors.
  • npx vitest run --maxWorkers=2 server/store/store.test.ts server/store/readings.test.ts web/src/mock: 106 tests passed.

GitHub CI run 47453783586 for head 478687e6 is not green. Passed: typecheck · lint · unit · build, e2e (control channel), e2e (desktop 1/3), e2e (phone · duo). Failed: e2e (desktop 3/3), e2e (desktop 2/3), typecheck · lint · unit · build · e2e.

The terminal desktop failures were pool-surfaces.spec.ts:188 (a swap row remained when zero were expected) and skins.spec.ts:51 (skin-css was not the last head element). Re-ran those two tests three times each on unmodified main and on this head: all six passed on each checkout (npx playwright test test/e2e/pool-surfaces.spec.ts test/e2e/skins.spec.ts --project=desktop --grep "the session page keeps|picking the fixture skin" --repeat-each=3 --workers=2). This did not reproduce the runner failures or establish their cause, so the failed run remains a merge blocker.

A maintainer needs to rerun/investigate the failed jobs and aggregate gate. The upstream job-rerun API rejects this account with HTTP 403 for insufficient repository permissions.

Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

Copy link
Copy Markdown
Contributor Author

Merged current main (e8bfe999, v0.8.19) into this branch; the head is now 456f9e8b. The merge needed one resolution, in CHANGELOG.md: this PR's Unreleased entry stays above the new 0.8.19 section. No source file of this PR changed upstream.

CI run 47497341379 for head 456f9e8b passed every job: typecheck · lint · unit · build, e2e (desktop 1/3), e2e (desktop 2/3), e2e (desktop 3/3), e2e (phone · duo), e2e (control channel) and the aggregate typecheck · lint · unit · build · e2e gate.

The earlier run 47453783586 on 478687e6 failed e2e (desktop 2/3) and e2e (desktop 3/3). The assertions that failed there are in skins.spec.ts:51 (expected "skin-css", received "") and pool-surfaces.spec.ts:188 ([data-swap] count). Neither is specific to this branch: skins.spec.ts:51 also failed its first attempt in run 46438821710 on feat/sidebar-rename, and pool-surfaces.spec.ts:188 failed both attempts today in run 47497357272 on #277, which changes only server/search/sources/text.ts. Both pass in the new run with the same source.

Locally on 456f9e8b (macOS, Node 22.23.2): npm run typecheck, npm run lint (135 warnings, no errors, as on main) and npm run build passed; npx vitest run server/store/store.test.ts server/store/readings.test.ts web/src/mock: 106 tests passed.

This branch has not been deployed

No deployments
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