Skip to content

feat(session): implement session store for persisting ACP session IDs… - #712

Merged
pikann merged 4 commits into
masterfrom
feature/implement-acp-bridge-session-store-functionality
Nov 8, 2026
Merged

pikann merged 4 commits into
masterfrom
feature/implement-acp-bridge-session-store-functionality

Conversation

@pikann

@pikann pikann commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Replying to an ACP agent conversation could start a brand-new conversation with no memory of the earlier turns. The bridge kept the ACP sessionId only in memory, so whenever the agent subprocess was respawned it called session/new and the agent started blank. That happened after:

  • idle eviction (default 30 minutes),
  • a force-kill when the agent ignored session/cancel,
  • a bridge restart.

Changes (apps/acp-bridge)

  • acpclient: Initialize now reads agentCapabilities.loadSession; added SupportsLoadSession() and LoadSession() (session/load).
  • runner/sessionstore.go (new): persists session ids to <user config dir>/paca-acp-bridge/<hash(workspace)>/<agent-id>/sessions.json (never inside the workspace), keyed by provider + session key. Writes re-read and merge the file. Best-effort; any I/O error just means a fresh session. runner.Config gains AgentID and StateDir.
  • runner.ensureSession: when respawning, tries session/load with the saved id first; falls back to session/new (with a warning) if the agent doesn't support it or the load fails. The new id is saved after each session is established.
  • History replayed by session/load arrives as session/update notifications; these are dropped while loading so they don't show up as duplicate transcript events.
  • Tests: store persistence/merge/path isolation, plus end-to-end runner tests (fake agent) for session/load on respawn, replay suppression, fallback to session/new on load failure, and no load without the capability.

Testing

  • go build, go vet, go test ./... pass in apps/acp-bridge.
  • Not yet verified against a real agent (Claude Code / Codex). Manual check: set PACA_SESSION_IDLE_MINUTES=1, send a message, wait ~2 minutes, reply; the agent should remember the earlier turn (requires the agent to support session/load).

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The resume flow itself looks sound, but the store currently lands inside the ACP workspace (the user's repository), and its identity omits the agent id while every daemon in that directory shares one file — please take a look before merging.

Reviewed changes

  • acpclient load capability + session/load — Initialize now records agentCapabilities.loadSession and LoadSession resumes an existing session, returning the same mode/model/config-option shape as session/new.
  • Resume on respawn — Runner.ensureSession looks up a persisted session id, loads it when the agent supports it, falls back to session/new on failure, and persists whichever id it ends up with.
  • Replay suppression — conversationState.loading is set around session/load, so the agent's replayed history notifications are dropped instead of re-forwarded as new transcript events.
  • sessionStore — a mutex-guarded JSON map at <workspace>/.paca-bridge/sessions.json keyed by provider|session-key, written atomically via tmp file + rename.
  • Store test — covers persistence across instances and provider isolation.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — the incremental delta since the prior review (cd9b507..13818b5), covering the session store's relocation, agent scoping, and the new resume tests.

  • Moved the store out of the workspace — storePath now resolves <stateDir>/<hash(workspace)>/<agentID>/sessions.json, defaulting to os.UserConfigDir()/paca-acp-bridge, so the daemon no longer creates runtime state in the user's repository.
  • Scoped the store to the agent and workspace — the path includes the agent id and the absolute workspace hash, so two agents in one project no longer share or clobber each other's sessions.json.
  • Merged on write — set re-reads the on-disk file before writing so a concurrent writer's entries are not lost, and the directory is now 0700.
  • Threaded the agent id through the CLI — runner.Config gains AgentID and StateDir, and cli.Main passes --agent-id.
  • Added resume-path coverage — the fake agent now advertises loadSession, replays a session/update before the session/load response, and logs the session calls; end-to-end tests cover load plus replay suppression, session/new fallback on load failure, and skipping load without the capability.
  • Added store tests — round-trip, provider isolation, concurrent-writer merge, and path isolation by workspace and agent outside the workspace.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — the incremental delta since the prior Pullfrog review (bbe307d..7027f64): session-store hardening around stale entries, path identity, and atomic writes.

  • Pruned stale sessions — entries now carry an updated timestamp, and anything older than 30 days is dropped when the store is written, so the file no longer grows without bound as tasks come and go.
  • Hardened the agent-id path component — storePath reduces the agent id with filepath.Base and falls back to default for ""/./.., so a caller-supplied id can no longer escape the state directory.
  • Made writes collision-safe — the fixed sessions.json.tmp name shared by concurrent daemons is replaced with os.CreateTemp in the target directory, and the temp file is removed on any write/close/rename failure.
  • Suppressed redundant writes and surfaced corrupt stores — re-setting an unchanged id within an hour skips the rewrite, and an unreadable sessions.json now logs a warning via the logger threaded into the store instead of failing silently.
  • Added coverage — tests for agent-id traversal rejection and 30-day pruning through a real file round-trip.

go build ./..., go vet ./..., gofmt -l ., and go test ./... pass in apps/acp-bridge at 7027f64.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit 6b4f151 into master Nov 8, 2026
4 checks passed
@pikann
pikann deleted the feature/implement-acp-bridge-session-store-functionality branch November 8, 2026 05:07
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