📝 Bug Description
CloudStore.WriteChunk reports success when replaying an identical existing cloud chunk even if rebuilding its session index fails. The matching-payload branch discards the result of indexChunkSessions and returns nil (internal/cloud/cloudstore/cloudstore.go). This can acknowledge an incomplete replay while cloud_project_sessions remains unavailable or out of date; the index is consumed by KnownSessionIDs. This report does not claim observed production data loss.
🔄 Steps to Reproduce
- In a disposable Go test for package
internal/cloud/cloudstore, use a fake database/sql/driver whose QueryContext returns the exact stored payload for SELECT payload::text FROM cloud_chunks.
- Use a payload with one session ID and a matching
chunkIDFromPayload(payload). Make the driver's ExecContext return an injected error for INSERT INTO cloud_project_sessions, recording that the insert was attempted.
- Call
CloudStore.WriteChunk with the matching project, chunk ID, payload and valid timestamp. Observe one failed index attempt while the method returns nil.
This was executed through a temporary Go overlay mapped to a package-local _test.go, without touching a real database or modifying the repository. The overlay was removed afterward. The focused command was go test -overlay <temporary-overlay.json> ./internal/cloud/cloudstore -run '^TestWriteChunkReplayIgnoresSessionIndexFailure$' -count=1 -v; <temporary-overlay.json> denotes the ephemeral fixture, not a checked-in file.
✅ Expected Behavior
If session-index rebuilding fails during an identical chunk replay, WriteChunk returns that error so the caller can distinguish an incomplete replay from a completed one and retry safely. A successful identical replay remains idempotent and does not duplicate mutations.
❌ Actual Behavior
The index insert returned an injected error, but WriteChunk returned nil. The current code uses _ = cs.indexChunkSessions(ctx, project, payload) before returning success. A temporary test asserting the defective behavior passed; its output is below.
Operating System
Windows
Engram Version
2.2.1 (installed CLI and source baseline used for the isolated test)
Agent / Client
Other
📋 Relevant Logs
=== RUN TestWriteChunkReplayIgnoresSessionIndexFailure
repro_replay_test.go:56: REPRODUCED: session index write returned injected session index failure but WriteChunk replay returned nil
--- PASS: TestWriteChunkReplayIgnoresSessionIndexFailure (0.00s)
PASS
💡 Additional Context
indexChunkSessionsWith wraps the failed insert error, but the existing-payload replay branch discards it. Existing TestWriteChunkMaterializesMutationsAndIsReplayIdempotent covers healthy replay, not index failure. First add a permanent package test that expects an error from this path (RED on current code), then propagate it and verify healthy replay/idempotence remains unchanged. This is separate from changing the chunk payload or broadening sync policy. No real PostgreSQL instance or user store was used in the reproduction.
📝 Bug Description
CloudStore.WriteChunkreports success when replaying an identical existing cloud chunk even if rebuilding its session index fails. The matching-payload branch discards the result ofindexChunkSessionsand returnsnil(internal/cloud/cloudstore/cloudstore.go). This can acknowledge an incomplete replay whilecloud_project_sessionsremains unavailable or out of date; the index is consumed byKnownSessionIDs. This report does not claim observed production data loss.🔄 Steps to Reproduce
internal/cloud/cloudstore, use a fakedatabase/sql/driverwhoseQueryContextreturns the exact stored payload forSELECT payload::text FROM cloud_chunks.chunkIDFromPayload(payload). Make the driver'sExecContextreturn an injected error forINSERT INTO cloud_project_sessions, recording that the insert was attempted.CloudStore.WriteChunkwith the matching project, chunk ID, payload and valid timestamp. Observe one failed index attempt while the method returnsnil.This was executed through a temporary Go overlay mapped to a package-local
_test.go, without touching a real database or modifying the repository. The overlay was removed afterward. The focused command wasgo test -overlay <temporary-overlay.json> ./internal/cloud/cloudstore -run '^TestWriteChunkReplayIgnoresSessionIndexFailure$' -count=1 -v;<temporary-overlay.json>denotes the ephemeral fixture, not a checked-in file.✅ Expected Behavior
If session-index rebuilding fails during an identical chunk replay,
WriteChunkreturns that error so the caller can distinguish an incomplete replay from a completed one and retry safely. A successful identical replay remains idempotent and does not duplicate mutations.❌ Actual Behavior
The index insert returned an injected error, but
WriteChunkreturnednil. The current code uses_ = cs.indexChunkSessions(ctx, project, payload)before returning success. A temporary test asserting the defective behavior passed; its output is below.Operating System
Windows
Engram Version
2.2.1 (installed CLI and source baseline used for the isolated test)
Agent / Client
Other
📋 Relevant Logs
=== RUN TestWriteChunkReplayIgnoresSessionIndexFailure repro_replay_test.go:56: REPRODUCED: session index write returned injected session index failure but WriteChunk replay returned nil --- PASS: TestWriteChunkReplayIgnoresSessionIndexFailure (0.00s) PASS💡 Additional Context
indexChunkSessionsWithwraps the failed insert error, but the existing-payload replay branch discards it. ExistingTestWriteChunkMaterializesMutationsAndIsReplayIdempotentcovers healthy replay, not index failure. First add a permanent package test that expects an error from this path (RED on current code), then propagate it and verify healthy replay/idempotence remains unchanged. This is separate from changing the chunk payload or broadening sync policy. No real PostgreSQL instance or user store was used in the reproduction.