Read known sessions as paged active-branch streams #6

Closed
opened 2026-08-28 19:24:38 +00:00 by dikka · 1 comment
Owner

What to build

Introduce the deliberate SessionHistorySource seam for listing metadata and reading normalized active-branch history. Its initial local Pi adapter uses Pi's public settings and SessionManager behavior with exact known paths. Hub callers and browser history routes depend on this narrow interface rather than reimplementing Pi's filesystem layout.

Open a known stopped or idle workspace session as one chronological stream containing persisted ordinary user entries and finalized assistant entries from Pi's current active branch. Do not show abandoned branches or expose session-tree navigation. Older history loads upward in bounded cancellable pages, preserves the visible entry and pixel offset, and remains rendered for the current page visit.

This is the first replacement slice for the current assistant-response chooser. Retain canonical finalized-response rendering so later annotation work can build on the stream rather than introducing a second document model.

Acceptance criteria

  • SessionHistorySource has a small documented interface for metadata/listing and bounded normalized active-branch reads.
  • The local adapter honors Pi's resolved session settings and exact catalog paths instead of scanning an invented Pilcrow directory convention.
  • A known session opens as chronological persisted user and finalized assistant entries from only the active branch.
  • The stream uses stable Pi entry identities and keeps finalized response canonical text immutable.
  • Approaching the top loads a bounded earlier page; cancellation and failure produce a local retry path.
  • Prepending entries preserves the visible anchor and loaded pages remain present for the page visit.
  • Live and cold fixtures passed through the history interface normalize equivalent durable entries identically.
  • Focused source-contract, hub history, rendered stream, and canonical response tests pass.

Blocked by

  • #3 — Establish the next exact producer interface
  • #4 — Persist terminal-observed sessions as workspace records

Human checkpoint note: Do not request routine per-ticket approval. The implementing agent may make the internal architecture, refactoring, testing, and UI-detail decisions needed to satisfy the acceptance criteria. Pause only if implementation requires a material product or ownership change, a destructive or hard-to-reverse action, excluded security or deployment scope, credentials or spending, or a real-browser design fork with no safe default. Forgejo completion updates may be batched with the rest of the completed frontier. The user performs final hub and Pi restart steps. Agents must not start, restart, replace, or stop the user-run Pilcrow development server.

## What to build Introduce the deliberate SessionHistorySource seam for listing metadata and reading normalized active-branch history. Its initial local Pi adapter uses Pi's public settings and SessionManager behavior with exact known paths. Hub callers and browser history routes depend on this narrow interface rather than reimplementing Pi's filesystem layout. Open a known stopped or idle workspace session as one chronological stream containing persisted ordinary user entries and finalized assistant entries from Pi's current active branch. Do not show abandoned branches or expose session-tree navigation. Older history loads upward in bounded cancellable pages, preserves the visible entry and pixel offset, and remains rendered for the current page visit. This is the first replacement slice for the current assistant-response chooser. Retain canonical finalized-response rendering so later annotation work can build on the stream rather than introducing a second document model. ## Acceptance criteria - [ ] SessionHistorySource has a small documented interface for metadata/listing and bounded normalized active-branch reads. - [ ] The local adapter honors Pi's resolved session settings and exact catalog paths instead of scanning an invented Pilcrow directory convention. - [ ] A known session opens as chronological persisted user and finalized assistant entries from only the active branch. - [ ] The stream uses stable Pi entry identities and keeps finalized response canonical text immutable. - [ ] Approaching the top loads a bounded earlier page; cancellation and failure produce a local retry path. - [ ] Prepending entries preserves the visible anchor and loaded pages remain present for the page visit. - [ ] Live and cold fixtures passed through the history interface normalize equivalent durable entries identically. - [ ] Focused source-contract, hub history, rendered stream, and canonical response tests pass. ## Blocked by - #3 — Establish the next exact producer interface - #4 — Persist terminal-observed sessions as workspace records > **Human checkpoint note:** Do not request routine per-ticket approval. The implementing agent may make the internal architecture, refactoring, testing, and UI-detail decisions needed to satisfy the acceptance criteria. Pause only if implementation requires a material product or ownership change, a destructive or hard-to-reverse action, excluded security or deployment scope, credentials or spending, or a real-browser design fork with no safe default. Forgejo completion updates may be batched with the rest of the completed frontier. The user performs final hub and Pi restart steps. Agents must not start, restart, replace, or stop the user-run Pilcrow development server.
Author
Owner

Implemented in jj revision 5bc35897 (feat(history): add bounded persisted active-branch response browsing).

What changed:

  • Deepened SessionHistorySource into the narrow Pi-facing interface for settings/session-directory metadata, exact-path validation, and bounded normalized active-branch reads. The adapter uses Pi public settings/SessionManager behavior and never opens sessions through a write-capable migration path.
  • Known stopped/idle sessions open as one chronological stream of persisted ordinary user entries and finalized stop/length assistant entries from Pi’s current active branch only. Stable Pi entry IDs and canonical immutable assistant text are retained; abandoned branches, unfinished assistants, thinking, tools, summaries, and custom state are excluded.
  • Replaced caller-controlled leaf/before queries with hub-random opaque visits and cursors bound to workspace ID, exact Pi path/ID, authoritative history facts, and a fixed branch/file-prefix revision. Cursor tampering cannot select an abandoned branch.
  • Fixed snapshots use O_NOFOLLOW dev/inode identity and byte-prefix SHA-256 checks. Append after the fixed leaf is allowed; truncation, replacement, or fixed-prefix rewrite is rejected.
  • Historical capture and feedback authority is branch-bound. Branch change or invalidation purges visits, response authority, and rendered captures so stale/abandoned responses cannot be selected or submitted.
  • History visit and response caches have global/per-session count, encoded-byte, TTL, and LRU bounds, plus explicit visit close and selected-response promotion.
  • Eligibility is rechecked after async reads for exact identity/history, lifecycle, connection, busy/compacting/turn state. Indexing and normalization periodically yield and honor cancellation/deadlines.
  • Pages are bounded by actual serialized UTF-8 JSON bytes, including escaping and metadata.
  • Browser loading uses generation-owned requests, fixing the React StrictMode aborted-first-effect deadlock. Short viewports auto-load earlier pages until filled or exhausted; prepends retain the first visible entry ID and exact pixel offset.
  • Session-directory precedence is explicit override, PI_CODING_AGENT_SESSION_DIR, then settings; exact producer/catalog paths remain authoritative for known sessions.

Audit and regression coverage:

  • Fresh review found abandoned-branch cursor authority, stale branch response authorization, StrictMode loading deadlock, unbounded caches/CPU work, fixed-snapshot inconsistency, encoded-size undercounting, session-dir precedence, and short-viewport gaps. All were fixed before closure.
  • Added tampered cursor/leaf/before, branch switch/invalidation, historical capture/submission, busy/compacting/turn/blocked/post-await authority, fixed-prefix append/rewrite, timeout/abort, cache eviction, serialized-byte, exact Pi identity, StrictMode deferred abort, viewport fill, composed WorkspaceApp, and read-only JSONL metadata tests.
  • Targeted history/StrictMode stress passed five consecutive runs.

Validation:

  • Supervisor focused verification passed: 6 files / 121 tests.
  • Full suite passed: 64 files / 470 tests.
  • TypeScript no-emit check, hub build, production browser build, changed-file formatting, and git diff --check passed.
  • Whole-tree vp check remains blocked only by the unchanged pre-existing formatting issue in .dev/agents/triage-labels.md.

No Pi process was launched, no Pi JSONL was written or migrated, and no cold History/search/import, branch UI, live settlement, or placement behavior was added. No dev server was managed.

Implemented in jj revision `5bc35897` (`feat(history): add bounded persisted active-branch response browsing`). What changed: - Deepened `SessionHistorySource` into the narrow Pi-facing interface for settings/session-directory metadata, exact-path validation, and bounded normalized active-branch reads. The adapter uses Pi public settings/SessionManager behavior and never opens sessions through a write-capable migration path. - Known stopped/idle sessions open as one chronological stream of persisted ordinary user entries and finalized `stop`/`length` assistant entries from Pi’s current active branch only. Stable Pi entry IDs and canonical immutable assistant text are retained; abandoned branches, unfinished assistants, thinking, tools, summaries, and custom state are excluded. - Replaced caller-controlled leaf/before queries with hub-random opaque visits and cursors bound to workspace ID, exact Pi path/ID, authoritative history facts, and a fixed branch/file-prefix revision. Cursor tampering cannot select an abandoned branch. - Fixed snapshots use O_NOFOLLOW dev/inode identity and byte-prefix SHA-256 checks. Append after the fixed leaf is allowed; truncation, replacement, or fixed-prefix rewrite is rejected. - Historical capture and feedback authority is branch-bound. Branch change or invalidation purges visits, response authority, and rendered captures so stale/abandoned responses cannot be selected or submitted. - History visit and response caches have global/per-session count, encoded-byte, TTL, and LRU bounds, plus explicit visit close and selected-response promotion. - Eligibility is rechecked after async reads for exact identity/history, lifecycle, connection, busy/compacting/turn state. Indexing and normalization periodically yield and honor cancellation/deadlines. - Pages are bounded by actual serialized UTF-8 JSON bytes, including escaping and metadata. - Browser loading uses generation-owned requests, fixing the React StrictMode aborted-first-effect deadlock. Short viewports auto-load earlier pages until filled or exhausted; prepends retain the first visible entry ID and exact pixel offset. - Session-directory precedence is explicit override, `PI_CODING_AGENT_SESSION_DIR`, then settings; exact producer/catalog paths remain authoritative for known sessions. Audit and regression coverage: - Fresh review found abandoned-branch cursor authority, stale branch response authorization, StrictMode loading deadlock, unbounded caches/CPU work, fixed-snapshot inconsistency, encoded-size undercounting, session-dir precedence, and short-viewport gaps. All were fixed before closure. - Added tampered cursor/leaf/before, branch switch/invalidation, historical capture/submission, busy/compacting/turn/blocked/post-await authority, fixed-prefix append/rewrite, timeout/abort, cache eviction, serialized-byte, exact Pi identity, StrictMode deferred abort, viewport fill, composed WorkspaceApp, and read-only JSONL metadata tests. - Targeted history/StrictMode stress passed five consecutive runs. Validation: - Supervisor focused verification passed: 6 files / 121 tests. - Full suite passed: 64 files / 470 tests. - TypeScript no-emit check, hub build, production browser build, changed-file formatting, and `git diff --check` passed. - Whole-tree `vp check` remains blocked only by the unchanged pre-existing formatting issue in `.dev/agents/triage-labels.md`. No Pi process was launched, no Pi JSONL was written or migrated, and no cold History/search/import, branch UI, live settlement, or placement behavior was added. No dev server was managed.
dikka closed this issue 2026-08-28 23:43:45 +00:00
Sign in to join this conversation.
No description provided.