Skip to content

fix(sdk): recover once from an expired syncCode cache hit - #673

Open
miyaontherelay wants to merge 1 commit into
mainfrom
ms/native-c-sdk-recovery
Open

miyaontherelay wants to merge 1 commit into
mainfrom
ms/native-c-sdk-recovery

Conversation

@miyaontherelay

@miyaontherelay miyaontherelay commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Recover once when a content-addressed syncCode cache hit expires before Cloud copies the archive at run submission. The SDK retains the packed snapshot through the first submission, recognizes only the exact HTTP 503 workflow_code_unavailable refusal, then prepares a new run without a digest, uploads the same snapshot, and submits that new run once. It never retries the terminalized run ID, an ambiguous transport outcome, another refusal, or a cache miss. The spool is removed after success or final failure.

Closes #672. Follow-up to #666 for 2.0.52; no package publication or deployment in this PR.

Verification

Against #666's original cloud-run.ts, with the new tests kept and the source restored byte-for-byte afterward:

TMPDIR=/tmp node node_modules/vitest/vitest.mjs run tests/cloud-sync.test.ts -t 'cache hit disappears|makes only one recovery attempt|does not resubmit' --testTimeout=15000

Test Files  1 failed (1)
Tests       3 failed | 45 skipped (48)
controlled base-code test exit=1

At this head:

TMPDIR=/tmp node node_modules/vitest/vitest.mjs run tests/cloud-sync.test.ts tests/cloud-run.test.ts tests/cloud-read.test.ts --minWorkers=1 --maxWorkers=1 --testTimeout=20000

✓ tests/cloud-sync.test.ts (48 tests)
✓ tests/cloud-read.test.ts (47 tests)
✓ tests/cloud-run.test.ts (99 tests)
Test Files  3 passed (3)
Tests       194 passed (194)

npm run typecheck && npm run typecheck:tests && npm run build

> @relayflows/sdk@2.0.50 typecheck
> tsc --noEmit && tsc -p tsconfig.type-tests.json
> @relayflows/sdk@2.0.50 typecheck:tests
> tsc -p tsconfig.tests.json
> @relayflows/sdk@2.0.50 build
> tsc && node scripts/make-cli-executable.mjs
exit 0

git diff --check — exit 0.


Agent Relay sessions

  • codex session 01a13937 · opened via gh pr create · last active 2026-10-16

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Changes hosted run admission and syncCode upload/retry behavior for cache hits; mistakes could double-submit or mishandle terminalized runs, though recovery is narrowly gated and heavily tested.

Overview
Adds a single automatic recovery when runInCloud uses syncCode and Cloud returns 503 workflow_code_unavailable after a content-addressed code cache hit (the cached archive vanished before run admission).

On a cache hit the SDK now keeps the packed tree (packedForRecovery) instead of disposing it immediately. Submission is refactored behind a submit() helper with shared rewriteRunError handling. If that specific refusal occurs, it prepares a new run without a digest, uploads the same snapshot, updates synced to the new run ID, and submits once more—but not if prepare reuses the terminalized run ID, on transport errors, other refusal codes, or after a real upload (cache miss). The spool is disposed in a finally after success or failure.

onSubmit docs note it still fires once before the first submission even when a follow-up submission happens after cache expiry. Tests extend the cloud mock to return raw Response objects and cover happy-path recovery, one-attempt limits, and cases that must not retry.

Reviewed by Cursor Bugbot for commit 1a37e95. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f82fa09-6f50-4ee4-ade3-f9f24bfeecc4
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@capy-ai capy-ai 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.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

runInCloud now recovers once when a cached code archive disappears before Cloud can copy it.

  • Cloud runs recover once when a synced code cache entry expires.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Pack working tree] --> B[Prepare with digest]
  B --> C{Cache hit?}
  C -- No --> D[Upload archive]
  D --> E[Submit run once]
  C -- Yes --> F[Keep archive and submit]
  F --> G{503 workflow_code_unavailable?}
  G -- No --> H[Return result or error]
  G -- Yes --> I[Prepare without digest]
  I --> J{Different run ID?}
  J -- No --> K[Return error]
  J -- Yes --> L[Upload original archive]
  L --> M[Submit fresh run once]
  M --> H
  E --> H
  H --> N[Remove retained archive]
  K --> N
Loading

Reviews (1) · Last reviewed commit: "fix(sdk): recover once from vanished cod..." · Reviewed by Greptile

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.

SDK: recover once when syncCode cache expires before submission (2.0.52)

1 participant