Skip to content

id: turso_client pipeline chunks lose the session (rde_incoming vanishes mid-load) #8545

Closed

Description

@dezren39

Fix: turso_client pipeline chunks lose the session (rde_incoming vanishes mid-load)

Found by Codex review on PR #8544 (migration of the runtime-db-export machinery to pkgs/agent-backup/, #5976), comment 4534316362. The defect is pre-existing in the hatch original (tools/runtime-db-export/turso_client.py) — the migrated copy is verbatim, so both copies carry it.

Problem

When a history-enabled spec such as spec_m3.json loads a 100-row page, load_rows.py creates and populates the temporary rde_incoming table using more than 100 statements. The chunking loop in turso_client.py splits those statements into separate _pipeline calls, each appending close without preserving a session baton. Subsequent staging inserts and the history archive then run on a connection where rde_incoming does not exist, so normal paged exports can fail.

Fix direction (per the finding)

Preserve the same session across chunks, or keep the staging, archive, and merge operations together in one pipeline/session.

Scope notes

  • Fix in the canonical code copy (pkgs/agent-backup/turso_client.py) and mirror to the hatch original (or supersede it), so the copies do not diverge silently.
  • Needs a test that exercises a history-enabled load whose statement count crosses the chunk boundary, with the oracle: staging table persists across all chunks and the archive/merge steps see the staged rows.

Activity

  1. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 11, 2026
  2. developing-today commented on Nov 11, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: triaged
    task: 18687 (queue repo-health-code-pilot, worker repo-worker-code, lane code-d)

    Triage verdict for issue #8545: TRIAGED — real, well-scoped bug with fix direction and test oracle in the issue; defect verified present at origin/main this shift (2026-11-17).

    • Issue id: turso_client pipeline chunks lose the session (rde_incoming vanishes mid-load) #8545 OPEN, no hard-stop labels (only app/id). Work kind: kind/bug + task/small-fix, priority/normal, effort/m — labels applied with this note.
    • Fresh verification: pkgs/agent-backup/turso_client.py at origin/main carries the described chunking (line 375: "chunk into pipeline calls of at most 100 statements"; separate _pipeline calls at lines 383/390) — the session-baton loss Codex flagged on PR docs: migrate backup scripts & backup documentation from hatch (#5976) #8544 (comment 4534316362) is in the shipped code, not just the migrated copy.
    • First concrete step for the follow-on: reproduce with a history-enabled spec whose statement count crosses 100, then preserve the session across chunks (or hold staging+archive+merge in one session), and mirror the fix to the hatch original per the issue's scope notes.
    • Follow-on: fix packet enqueued as task 20172 (dedupe repo-health:v1:fix:developing-today/code:issue:8545). Completing task 18687 as triaged naming task 20172.
  4. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    priority/normalOrdinary priority (the default)
    effort/mMedium: expected under 1 day of work
    on Nov 17, 2026
  5. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up (task 20172)

    • Agent: queue worker (repo-worker-code), lane any-m
    • Session / ID: task 20172
    • Found via: queue claim (unfiltered, one-queue)

    Revalidated fresh: issue #8545 OPEN, labels kind/bug, task/small-fix, priority/normal, app/id, effort/m — no hard-stop labels. Next: read pkgs/agent-backup/turso_client.py chunking, reproduce a cross-chunk history-enabled load losing rde_incoming, preserve the session across chunks, mirror to the hatch original, add the boundary test.

  6. added a commit that references this issue on Nov 17, 2026
  7. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (task 20172, fixed_merged)

    • Agent: queue worker (repo-worker-code), lane any-m
    • Session / ID: task 20172

    Outcome: PR #11258 merged (84c07af), issue #8545 auto-closed.

    • Fix (pkgs/agent-backup/turso_client.py): the client now carries the libsql session baton across the pipeline chunks of one batch — _pipeline(statements, close=…) sends the stored baton, records the returned one, and only the final chunk of execute closes; a mid-batch failure drops the session best-effort so its temp tables can't leak into the next batch. Before this, each ≤100-statement chunk ran on a fresh session, so the CREATE TEMP + 100 INSERTs + archive INSERT..SELECT shape in load_rows lost rde_incoming at the first chunk boundary.
    • Mirror: the identical fix was applied to the hatch original ~/tools/runtime-db-export/turso_client.py in the same pass (outside this repo), with the same test file copied there and passing, so the copies do not diverge on this defect.
    • Tests: new pkgs/agent-backup/test_turso_client.py — a fake Hrana server whose sessions are separate in-memory SQLite DBs (faithful temp-table visibility). The cross-boundary staging test and the failed-batch session-drop test both fail on the pre-fix client and pass with the fix (verified by stashing, in both copies).
    • Reviews: Codex review quota-failed (no findings, zero inline comments); merged under standing authority on the local verification above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)status:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions