Skip to content

Add pi-session-drain Pi package#249

Open
rrvsh wants to merge 10 commits into
primefrom
add-pi-session-drain
Open

Add pi-session-drain Pi package#249
rrvsh wants to merge 10 commits into
primefrom
add-pi-session-drain

Conversation

@rrvsh

@rrvsh rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • add the pi-session-drain flake input
  • include the packaged extension in Pi agent settings via its Nix package path

Validation

  • nix flake show --all-systems --json
  • nix eval --json .#nixosConfigurations.nemesis.config.home-manager.users.rafiq.programs.pi-coding-agent.settings.packages | grep session-drain

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Post-PR validation on nemesis:

  • sudo nixos-rebuild switch --flake .#nemesis succeeded from the PR branch. New system: /nix/store/kwkgiinmj0h9jardk42qhzrhdbl4px7j-nixos-system-nemesis-26.11.20260610.9ae611a.
  • pi list shows /nix/store/hkl9vqhds8lj8s16zbpjbdp1q4s8vvhb-pi-session-drain-0.1.0/lib/node_modules/pi-session-drain.
  • Ran an isolated smoke test against the installed Nix package using a temporary HOME and synthetic session JSONL. Verified tool/command registration, session_drain_next, transcript omission behavior, session_drain_mark, processed filtering, and changed-session retry behavior.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Updated after status-model discussion:

  • pi-session-drain now uses DB statuses only: processed and failed.
  • Added session_drain_status.
  • /session-drain:status is read-only aggregate status.
  • Added /session-drain:drain, which marks the current active session processed before queuing the subagent drain workflow.
  • Deleted stale SPEC.md; README local testing now uses git clone ... && pi -e ..
  • Updated tools lock to rrvsh/pi-session-drain@cdb0d77.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/x2glgg8cwzfhc7j3dip18mgxrhs6clpj-nixos-system-nemesis-26.11.20260610.9ae611a
  • pi list shows /nix/store/rjb328xzd3cjisf3ssrccccbzchkasy1-pi-session-drain-0.1.0/lib/node_modules/pi-session-drain
  • Installed-package smoke test passed for status counts, next, transcript omissions, processed mark, changed-session requeue, failed retryable, and /session-drain:drain current-session processed behavior.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Follow-up clarification applied:

  • /session-drain:drain now only starts/queues the batch subagent drain loop.
  • Added /session-drain:drain-current to mark the current active persisted session as processed.
  • README updated accordingly.
  • Updated tools lock to rrvsh/pi-session-drain@665ff44.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • command-split smoke test verified drain does not mark current and drain-current does
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/m846r5gx5av4g9hqabxiszac3zqq4i70-nixos-system-nemesis-26.11.20260610.9ae611a
  • installed package includes both commands at /nix/store/90dxn4y13i1rdcnl2ylxkfqba3ryygxw-pi-session-drain-0.1.0/lib/node_modules/pi-session-drain

@rrvsh
rrvsh force-pushed the add-pi-session-drain branch from a30f1c3 to 6f7cd67 Compare July 17, 2026 03:05
@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Follow-up fixes for test findings:

  • Added a managed session-drain subagent from the extension itself. On session start the extension writes ~/.pi/agent/agents/session-drain.md only if missing or already marked managed-by: pi-session-drain; unmanaged existing files are left alone.
  • /session-drain:drain prompt now tells the parent to use the session-drain subagent.
  • Fixed status state write concurrency:
    • inter-process status.lock around read/append/write
    • unique temp file names using randomUUID()
    • clearer parse error for corrupted JSON state/config
  • Updated tools lock to rrvsh/pi-session-drain@63bcc7f.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • concurrency smoke test with parallel session_drain_mark calls preserved all records and valid JSON
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/qr0s2r5svwylpf5ivjvqq4d8vjx0hp9k-nixos-system-nemesis-26.11.20260610.9ae611a
  • managed agent was installed and subagent({ action: "list" }) shows session-drain
  • subagent tool-access smoke test: session-drain child successfully called session_drain_transcript and returned 33 entries
  • installed-package concurrency smoke test passed.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Chunked transcript drain update:

  • Added session_drain_chunks for metadata-only chunk planning.
  • Extended session_drain_transcript with optional until_line, plus range_complete and session_complete.
  • Replaced managed session-drain with session-drain-chunk; stale managed session-drain.md is removed.
  • session-drain-chunk has only session_drain_transcript and reports candidates only; parent owns synthesis/memory edits.
  • Updated /session-drain:drain prompt to plan chunks, fan out chunk workers, synthesize in parent, and mark processed/failed.
  • Updated tools lock to rrvsh/pi-session-drain@8b5ad5a.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • chunk smoke test for 125-entry synthetic transcript: two chunks, ranged transcript returned first 100 entries with range_complete: true, session_complete: false
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/4vlhzg5rkd18kcilwzvx296qbvsrl4r5-nixos-system-nemesis-26.11.20260610.9ae611a
  • managed agent sync installed session-drain-chunk.md and removed stale managed session-drain.md
  • subagent({ action: "list" }) shows session-drain-chunk
  • session-drain-chunk tool-access smoke test called session_drain_transcript for one bounded chunk and returned Outcome: chunk-processed
  • installed-package chunk smoke test passed.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Follow-up chunk/research/batch-mark update:

  • session-drain-chunk now has read-only research tools: read, grep, find, ls, plus session_drain_transcript; still no edit/write/mark tools.
  • Chunk agent prompt requires transcript tool as authoritative source, allows bounded local read-only research, and requires source references.
  • session_drain_chunks now returns top-level session_path and session_dir.
  • /session-drain:drain now tells parent to pass session path/dir and includes the synthesis checklist.
  • Added session_drain_mark_many for one locked batch transaction.
  • Updated tools lock to rrvsh/pi-session-drain@fa8245d.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • smoke test verified chunk path/dir, managed agent tools, and session_drain_mark_many
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/v6a98vm0qsa1i2zr4zrrwjyh6g74nvay-nixos-system-nemesis-26.11.20260610.9ae611a
  • managed installed agent now shows tools: read, grep, find, ls, session_drain_transcript
  • session-drain-chunk subagent tool-access smoke test succeeded with transcript + read-only research tools
  • installed-package smoke test for chunk path/dir and session_drain_mark_many passed.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Next now returns chunks update:

  • session_drain_next now treats limit as a chunk budget. Default remains 1.
  • session_drain_next returns complete sessions with embedded chunks and rounds down to preserve session boundaries.
  • Added optional session_id to session_drain_next for oversized-session retry.
  • Oversized first session now returns no sessions plus oversized_session_id, oversized_chunk_count, and required_limit; parent prompt tells agent to retry with that session_id and required_limit.
  • Kept session_drain_chunks for targeted/debug planning.
  • Updated /session-drain:drain prompt to use chunks embedded in next and not call chunks in normal path.
  • Updated tools lock to rrvsh/pi-session-drain@4059656.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • smoke test covered chunk-budget limit, session-boundary rounding, oversized response, and session_id retry
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/wvz4bs1blb84si59ky7zfrai76h977rk-nixos-system-nemesis-26.11.20260610.9ae611a
  • installed-package next chunk-budget smoke test passed.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Child-session exclusion update:

  • Detect nested subagent child sessions from path shape <parent-stem>/<8hex>/run-N/session.jsonl.
  • Add relationship metadata on discovered child sessions: is_subagent_child, parent_session_id, parent_session_path, parent_status, run_id, child_index.
  • Exclude child sessions by default from session_drain_status, session_drain_next, session_drain_chunks, and session_drain_transcript.
  • Add explicit opt-in include_child_sessions: true for inspection/debugging.
  • Status now reports excluded_child_sessions.
  • Updated tools lock to rrvsh/pi-session-drain@1888dd7.

Validation:

  • npm run typecheck
  • nix build .#pi-session-drain --print-build-logs
  • smoke test verified default status counts only parent sessions, reports excluded child count, next returns only parent sessions, child chunks/transcript fail by default, and explicit opt-in returns child metadata/access
  • sudo nixos-rebuild switch --flake .#nemesis succeeded; new system /nix/store/sxsymnz0rjw6zw0399jn1wcc9n90gcj2-nixos-system-nemesis-26.11.20260610.9ae611a
  • installed-package child-exclusion smoke test passed.

@rrvsh

rrvsh commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Added manual session drain service, no timer yet.

  • Added Home Manager wrapper pi-session-drain-run.
  • Wrapper runs pi --no-session -p <direct drain prompt>, with PI_OFFLINE=1 and PI_SKIP_VERSION_CHECK=1.
  • Added user oneshot service pi-session-drain.service.
  • Did not add timer yet.
  • Rebuilt nemesis: /nix/store/4pdqh3naxqld6vc2frkm1q5f78m2lck8-nixos-system-nemesis-26.11.20260610.9ae611a.
  • Started service with systemctl --user start --no-block pi-session-drain.service.
  • Verified service is active/starting and parent session JSONL count did not increase immediately after start.
  • Added follow-up todo to check results after the real drain finishes before deciding on a timer.

Commit: a382ff35 Add manual session drain service.

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