Skip to content

fix: retry enricher when tool-call found but result not yet written - #2

Merged
antonvp merged 1 commit into
mainfrom
fix/enricher-retry
Apr 2, 2026
Merged

fix: retry enricher when tool-call found but result not yet written#2
antonvp merged 1 commit into
mainfrom
fix/enricher-retry

Conversation

@antonvp

@antonvp antonvp commented Apr 2, 2026

Copy link
Copy Markdown
Owner

TL;DR

Fixes a race condition where enrich() returned null for the result even when the tool-call was found in store.db. Cursor fires the ACP "completed" event before flushing the result blob, so the retry loop was exiting early with a partial result.

Summary

  • Extended the retry condition to also retry when result.result === null (call found but result not yet written), not only when the blob is missing entirely
  • Tracks the best partial result seen during retries; returns it on timeout instead of null, so callers still get args/toolName even if the result never arrives
  • Two new tests: async DB write simulation (race condition recovery) and timeout-fallback behavior
  • Prettier formatting applied to test file

Testing

  • 19 unit tests passing (2 new tests cover the race condition and timeout fallback)
  • Revert-test-restore cycle confirmed: new tests fail without the fix, pass with it
  • Full prepublishOnly gate (typecheck + lint + format:check + build + test) will run on publish

Adds a retry when readToolCallBlob returns a non-null object with
result: null — which happens when the tool-call blob is present but
the paired tool-result hasn't been flushed yet. Previously the retry
loop was only entered when the blob was missing entirely (null).

Also returns the best partial result (args populated) on timeout
instead of null, so callers get at least the tool name and args.

Two new tests cover both the race-condition recovery and the
timeout-fallback behaviour.
@antonvp
antonvp merged commit 2d5487e into main Apr 2, 2026
1 check passed
@antonvp
antonvp deleted the fix/enricher-retry branch April 2, 2026 23:02
antonvp added a commit that referenced this pull request Apr 3, 2026
Adds a retry when readToolCallBlob returns a non-null object with
result: null — which happens when the tool-call blob is present but
the paired tool-result hasn't been flushed yet. Previously the retry
loop was only entered when the blob was missing entirely (null).

Also returns the best partial result (args populated) on timeout
instead of null, so callers get at least the tool name and args.

Two new tests cover both the race-condition recovery and the
timeout-fallback behaviour.

Co-authored-by: Anton Pavlov <anton@loris.ai>
antonvp added a commit that referenced this pull request Apr 3, 2026
Adds a retry when readToolCallBlob returns a non-null object with
result: null — which happens when the tool-call blob is present but
the paired tool-result hasn't been flushed yet. Previously the retry
loop was only entered when the blob was missing entirely (null).

Also returns the best partial result (args populated) on timeout
instead of null, so callers get at least the tool name and args.

Two new tests cover both the race-condition recovery and the
timeout-fallback behaviour.

Co-authored-by: Anton Pavlov <anton@loris.ai>
antonvp added a commit that referenced this pull request Apr 3, 2026
Adds a retry when readToolCallBlob returns a non-null object with
result: null — which happens when the tool-call blob is present but
the paired tool-result hasn't been flushed yet. Previously the retry
loop was only entered when the blob was missing entirely (null).

Also returns the best partial result (args populated) on timeout
instead of null, so callers get at least the tool name and args.

Two new tests cover both the race-condition recovery and the
timeout-fallback behaviour.
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.

2 participants