Skip to content

fix(acp): warn on session persistence failures#487

Open
Ashwinhegde19 wants to merge 1 commit into
Gitlawb:mainfrom
Ashwinhegde19:fix-acp-persistence-warnings
Open

fix(acp): warn on session persistence failures#487
Ashwinhegde19 wants to merge 1 commit into
Gitlawb:mainfrom
Ashwinhegde19:fix-acp-persistence-warnings

Conversation

@Ashwinhegde19

@Ashwinhegde19 Ashwinhegde19 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #471

Summary

  • surface ACP session history load failures as non-fatal warning thought chunks
  • surface turn persistence append failures as non-fatal warning thought chunks
  • keep prompt turns and in-memory continuity working when persistence fails

Tests

  • go test ./internal/acp -count=1
  • make lint
  • make test-quick

Summary by CodeRabbit

  • Bug Fixes
    • Improved session history loading to proceed when history can’t be read, and emit a warning while still completing the prompt.
    • Improved turn persistence so partial save failures produce a warning rather than being silently ignored.
    • Ensured warning/thought messages are emitted consistently during streaming.
  • Tests
    • Added end-to-end coverage for persistence failures and corrupted session history, verifying that warnings are shown and the prompt still completes.

Copilot AI review requested due to automatic review settings July 4, 2026 13:10

Copilot AI 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.

Pull request overview

This PR addresses ACP session persistence failures that were previously ignored by surfacing them as non-fatal warning “thought” chunks, while preserving in-memory continuity so turns still work even when on-disk history cannot be read or appended.

Changes:

  • Add a notifier.warning helper that emits warnings via agent_thought_chunk.
  • Return and propagate persistence/load errors from persistTurn and loadHistory, emitting warnings instead of silently ignoring failures.
  • Add end-to-end ACP tests covering warning emission and continued prompt/load behavior under persistence corruption/failure.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/acp/translate.go Adds a notifier warning helper that routes warnings through thought chunks.
internal/acp/agent.go Stops silently swallowing store errors; surfaces load/append failures as non-fatal warnings while keeping in-memory history updated.
internal/acp/agent_test.go Adds tests asserting persistence/load failures produce warning thought chunks and do not abort prompt/load flows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9c55488a-fca0-4863-853b-a4e43f8e0b81

📥 Commits

Reviewing files that changed from the base of the PR and between 4a04b73 and 3253cd1.

📒 Files selected for processing (3)
  • internal/acp/agent.go
  • internal/acp/agent_test.go
  • internal/acp/translate.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/acp/translate.go
  • internal/acp/agent_test.go
  • internal/acp/agent.go

Walkthrough

Session history persistence and loading now return errors instead of discarding them, and those failures are surfaced as warning thought updates. The ACP test harness now separates thought chunks, and new end-to-end tests cover persistence and history-read failures.

Changes

Persistence and history-load error surfacing

Layer / File(s) Summary
Warning notifier helper
internal/acp/translate.go
Adds notifier.warning(message string) that forwards text to the existing thought method.
persistTurn and loadHistory error propagation
internal/acp/agent.go
persistTurn now returns an accumulated error from store append failures while still updating in-memory history; loadHistory now returns (records, error), propagating ReadEvents failures and returning nil, nil when no store is configured.
Wiring warnings into session load and prompt turn flows
internal/acp/agent.go
handleSessionLoad captures the loadHistory error and emits a warning while still registering the session; runTurn checks persistTurn's error and warns when persistence is incomplete.
Test harness support for thought/warning chunks
internal/acp/agent_test.go
Harness adds a thoughts channel; the notify handler routes thought chunks separately; drainText delegates to a generalized drainContains helper.
End-to-end persistence and load-failure warning tests
internal/acp/agent_test.go
Adds TestACPPromptWarnsWhenPersistenceFails and TestACPLoadWarnsWhenHistoryReadFails, each asserting a warning thought chunk while the operation still completes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: Vasanthdev2004, anandh8x

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: surfacing ACP session persistence failures as warnings.
Linked Issues check ✅ Passed The changes address #471 by warning on history-load and persistence-append failures while keeping sessions usable.
Out of Scope Changes check ✅ Passed The notifier and test-harness updates support the warning flow and stay within the issue's persistence-failure scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/acp/agent_test.go (1)

163-224: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Solid end-to-end coverage for the two warning paths.

Both tests correctly force real failures (directory-as-file, invalid JSON) and assert the RPC still succeeds while a warning thought chunk is emitted — this directly validates the persistTurn/loadHistory → notifier.warning contract from internal/acp/agent.go.

One optional gap: TestACPPromptWarnsWhenPersistenceFails checks StopReason but doesn't verify the assistant's actual message text still reaches h.updates, which would more fully confirm the "in-memory continuity" guarantee the PR objectives call out (persistence failing should not affect the delivered response). Consider adding that assertion for stronger coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/acp/agent_test.go` around lines 163 - 224,
TestACPPromptWarnsWhenPersistenceFails covers the warning path but does not
assert that the assistant response still reaches the in-memory update stream
when persistence fails. Update this test to also verify the delivered assistant
text via h.updates, using the existing harness and MethodSessionPrompt flow, so
it confirms continuity alongside the StopReason and warning thought chunk
checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/acp/agent_test.go`:
- Around line 163-224: TestACPPromptWarnsWhenPersistenceFails covers the warning
path but does not assert that the assistant response still reaches the in-memory
update stream when persistence fails. Update this test to also verify the
delivered assistant text via h.updates, using the existing harness and
MethodSessionPrompt flow, so it confirms continuity alongside the StopReason and
warning thought chunk checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53633b53-10e8-4661-8c0a-2c72f15c8fb5

📥 Commits

Reviewing files that changed from the base of the PR and between f401c66 and 4e19a38.

📒 Files selected for processing (3)
  • internal/acp/agent.go
  • internal/acp/agent_test.go
  • internal/acp/translate.go

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean and well-scoped. ACP persistence errors that were getting swallowed now surface as non-fatal warning chunks, and the in-memory history is kept unconditionally so the turn keeps working when the store fails. Traces correct, the tests cover both the load and the append failure paths, and there's nothing platform-specific. Approving.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread internal/acp/agent.go
}

// Serve runs the connection read loop until the stream closes or ctx is done.
func (a *Agent) Serve(ctx context.Context) error { return a.conn.Serve(ctx) }

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.

can you check this? its flagged by CI security as unreachable function

@kevincodex1 kevincodex1 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.

please check agent.go changes there is un unreachable function

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note

GitHub currently reports mergeStateStatus: BLOCKED even though the branch is mergeable from a conflict standpoint. The apparent blocker is the open requested-changes review about internal/acp/agent.go:87 being flagged as unreachable. I checked that line: Agent.Serve is unchanged from main, is a thin wrapper around Conn.Serve, and is used by the ACP test harness. The repo's CI security workflow documents the deadcode step as advisory/non-blocking, and the current Security & code health job passed. I do not see a code or security fix needed for that specific flag, but the outstanding review state still needs to be resolved before the PR can proceed.

Findings

  • [P3] Strengthen the persistence-failure test to verify in-memory continuity
    internal/acp/agent_test.go:163
    TestACPPromptWarnsWhenPersistenceFails correctly checks that the prompt succeeds and that a warning thought chunk is emitted, but it does not assert that the assistant's message text still reaches h.updates when persistence fails. Since the PR's stated goal includes keeping prompt turns and in-memory continuity working when persistence fails, please add an assertion such as drainContains(t, h.updates, "Hello from ZERO") so the test proves the warning path does not interrupt streamed assistant output.

@Ashwinhegde19 Ashwinhegde19 force-pushed the fix-acp-persistence-warnings branch from 4e19a38 to 4a04b73 Compare July 5, 2026 05:32

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving.

The persistence-failure test now asserts in-memory continuity the way you asked — drainContains(h.updates, "Hello from ZERO") proves the assistant's output still streams when the append fails, alongside the two warning-thought assertions for the load and append paths. That was the one open finding.

The deadcode flag on agent.go:87 is a non-issue — Serve is unchanged from main and that step is advisory, as you already found; nothing to fix there.

Marked the linked issue #471 issue-approved — silent persistence errors dropping session history is a real bug, and surfacing them as non-fatal warnings while keeping the turn and in-memory continuity alive is the right fix. CI is green.

Good to merge — over to kevin.

@Ashwinhegde19 Ashwinhegde19 force-pushed the fix-acp-persistence-warnings branch from 4a04b73 to 3253cd1 Compare July 5, 2026 09:21
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.

acp: silent errors in session persistence can lose history

5 participants