Skip to content

fix(gateway): prevent workspace sync truncation on short writes - #123739

Merged
steipete merged 1 commit into
mainfrom
steipete/autoqa-short-write-workspace-20260814
Aug 14, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/autoqa-short-write-workspace-20260814

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where workspace synchronization could truncate uploaded files, bounded command output, or generated transfer lists when the filesystem completed a legal positive short write. Reconcile uploads were eventually rejected by the staging manifest check, while the local inventory writers could return normally with incomplete files.

Why This Change Was Made

The workspace-sync owner now enforces full persistence at every raw file-handle boundary:

  • delegated reconcile uploads retry the unwritten suffix at exact source and file offsets;
  • delegated authority is revalidated after every awaited retry and zero-progress writes fail closed;
  • fresh sequential inventory and transfer-list writers use Node's full-write FileHandle.writeFile() primitive.

Existing byte limits, digest verification, staging isolation, completed-upload publication, and cleanup remain authoritative. This does not change protocol or persistent state.

User Impact

Workspace transfers no longer fail or silently emit truncated inventory files solely because an underlying write persisted only a positive prefix. Authority retirement and terminal write failures continue to remove staging and leave the upload unavailable.

Evidence

  • Pre-fix reconcile fault injection failed before the suffix could be persisted; staging validation rejected the truncated file.
  • Pre-fix sibling fault injection produced three normally returned but truncated outputs: bounded stdout, buffered Git transfer paths, and filtered NUL paths.
  • node scripts/run-vitest.mjs src/gateway/worker-environments/node-workspace-transfer-service.test.ts src/gateway/worker-environments/workspace-sync-local.test.ts — 13 tests passed.
  • node scripts/check-changed.mjs -- <five changed workspace paths> — passed on Blacksmith Testbox (tbx_01m00gepg8c19qbfw2e3fp2gt1): https://github.com/openclaw/openclaw/actions/runs/31817841929
  • Targeted oxfmt --check and git diff --check passed.
  • Fresh Codex-backed autoreview reported no accepted/actionable findings.
  • Production LOC: +18/-5 (net +13). The growth is the explicit positional retry loop required to preserve the delegated-authority fence after each awaited write; the three sequential sibling fixes are net zero. Tests: +278/-18.

Named follow-up: reset claimed uploads after failures that occur before the staging cleanup scope begins. That is a separate lifecycle defect and is intentionally not changed here.

AI-assisted; the final owner boundary, authority behavior, regressions, and proof were independently reviewed.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 14, 2026 16:24
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 12:32 PM ET / 16:32 UTC.

ClawSweeper review

What this changes

The PR retries positive short writes for staged workspace uploads and uses Node’s complete-write file API for locally generated workspace inventory and transfer-list files.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for maintainer sign-off after exact-head checks complete. The patch is a focused owner-boundary repair with no blocking correctness finding found.

Priority: P2
Reviewed head: 2fda60b0d8033844a96ff86a5ad8521b85c69fe3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-covered repair with no blocking finding; exact-head checks and the protected-label maintainer decision remain.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored gateway PR is exempt from the external-contributor proof gate; its branch nevertheless includes integration-level fault injection through the workspace-transfer runtime.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored gateway PR is exempt from the external-contributor proof gate; its branch nevertheless includes integration-level fault injection through the workspace-transfer runtime.
Evidence reviewed 5 items Current failure boundary: Current main advances the upload offset after one FileHandle write without checking bytesWritten; its inventory and transfer-list writers likewise await write without consuming a returned byte count.
Owner lifecycle is preserved: The upload owner calls streamUploadFile inside staging, validates the completed manifest, and removes staging plus clears the claimed upload on failure; the patch keeps that lifecycle and adds an authority assertion after every retry await.
Patch covers all identified raw file-handle writers: The PR adds positional suffix retries for uploads and replaces the three sequential local writes with writeFile, avoiding a second generic retry abstraction that would not carry upload offsets or authority state.
Findings None None.
Security None None.

How this fits together

Workspace sync writes uploaded worker changes into a staging area and generates local inventory files before manifest validation and reconciliation. These writers sit directly before the digest, staging-cleanup, and publication paths.

flowchart LR
  A[Worker workspace data] --> B[Workspace sync]
  B --> C[Staged upload writer]
  B --> D[Inventory and transfer writers]
  C --> E[Manifest validation]
  D --> E
  E --> F[Workspace reconciliation]
Loading

Decision needed

Question Recommendation
After exact-head checks complete, should this maintainer-owned workspace-sync integrity fix merge as reviewed? Merge after green checks: Accept the focused repair once required checks pass on the exact reviewed head.

Why: The PR carries the protected maintainer label, so automated cleanup must leave the merge decision to a human despite no blocking patch finding.

Before merge

  • Resolve merge risk (P1) - Production grows by 13 net lines; the local positional loop is warranted because this upload path must retain explicit offsets and revalidate delegated authority after each await.
  • Resolve merge risk (P1) - Exact-head checks are still queued, and the partial checkout could not retrieve Node API docs/types for an additional independent contract read because network DNS was unavailable.
  • Complete next step (P2) - The protected maintainer label requires human merge ownership; no mechanical repair is needed while exact-head checks remain pending.
Agent review details

Security

None.

PR surface

Source +13, Tests +260. Total +273 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 18 5 +13
Tests 2 278 18 +260
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 296 23 +273

Review metrics

Metric Value Why it matters
Production versus test LOC production +18/-5 (net +13); tests +278/-18 (net +260) The production growth is confined to the positional retry and authority fence; the larger test delta exercises short writes, cleanup, and sibling writers.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, durable storage schema: src/gateway/worker-environments/workspace-sync-local.test.ts, serialized state: src/gateway/worker-environments/workspace-sync-inventory.ts, serialized state: src/gateway/worker-environments/workspace-sync-local.ts, unknown-data-model-change: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, unknown-data-model-change: src/gateway/worker-environments/workspace-sync-local.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the local positional retry loop for staged uploads and the complete-write primitive for sequential files, then merge only after exact-head validation and maintainer sign-off.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the local positional retry loop for staged uploads and the complete-write primitive for sequential files, then merge only after exact-head validation and maintainer sign-off.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current writers ignore positive short-write results, and the branch’s fault-injection tests target the resulting truncated outputs. This read-only review did not execute the tests.

Is this the best way to solve the issue?

Yes, with a minor contract-review caveat: positional retries belong at the upload owner because they preserve offsets and authority fences, while sequential writers can use the complete-write primitive.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e74671df05e8.

Labels

Label changes:

  • add P2: This repairs a bounded but potentially silent workspace-transfer integrity failure without evidence of an active emergency.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored gateway PR is exempt from the external-contributor proof gate; its branch nevertheless includes integration-level fault injection through the workspace-transfer runtime.

Label justifications:

  • P2: This repairs a bounded but potentially silent workspace-transfer integrity failure without evidence of an active emergency.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored gateway PR is exempt from the external-contributor proof gate; its branch nevertheless includes integration-level fault injection through the workspace-transfer runtime.

Evidence

What I checked:

Likely related people:

  • iridescentWen: Current-main blame ties the unchecked inventory and filtered-list writes to the commit that introduced this workspace-transfer surface. (role: original workspace-write contributor; confidence: high; commits: 94cdb6c46e12; files: src/gateway/worker-environments/workspace-sync-inventory.ts, src/gateway/worker-environments/workspace-sync-local.ts)
  • steipete: Recent current-main history includes gateway transfer-service work in addition to this focused repair. (role: recent gateway contributor; confidence: high; commits: 530b33e4e372; files: src/gateway/worker-environments/node-workspace-transfer-service.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for exact-head required checks before merge.
  • Confirm the Node FileHandle contract in available CI or maintainer review if the unavailable local dependency documentation remains a concern.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 2fda60b0d8033844a96ff86a5ad8521b85c69fe3:

  • Pre-fix fault injection reproduced reconcile rejection after a positive short write and three normally returned but truncated local workspace outputs.
  • node scripts/run-vitest.mjs src/gateway/worker-environments/node-workspace-transfer-service.test.ts src/gateway/worker-environments/workspace-sync-local.test.ts — 13/13 passed.
  • Remote changed gate passed on Testbox tbx_01m00gepg8c19qbfw2e3fp2gt1: https://github.com/openclaw/openclaw/actions/runs/31817841929
  • Exact-head PR CI is green: https://github.com/openclaw/openclaw/actions/runs/31819224212
  • Targeted formatting and git diff --check passed.
  • Fresh Codex-backed autoreview: no accepted/actionable findings.
  • Latest ClawSweeper review and Rank-up moves read: exact-head checks are complete. Node's FileHandle contract was independently confirmed in official Node 24 source/docs and installed types; writeFile() retries positive short writes, while the upload's explicit positional loop retains the per-await delegated-authority fence.
  • Production delta is +13, confined to the positional retry/authority loop; the three sequential sibling repairs are net zero. No config, schema, protocol, or dependency changes.

Known proof gap: the separate pre-staging claimed-upload cleanup defect is not bundled; it is recorded as a named follow-up.

@steipete
steipete merged commit f8be386 into main Aug 14, 2026
235 of 244 checks passed
@steipete
steipete deleted the steipete/autoqa-short-write-workspace-20260814 branch August 14, 2026 17:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant