Repository navigation
perf(gateway): avoid preparing chat attachment workspaces twice - #184985
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR retains one live workspace preparation through chat attachment staging and releases it afterward. Example: Upload twelve 4 KiB text files to a sandboxed chat session.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR removes duplicate workspace preparation without an identified production regression. The prior SSH fixture finding is fixed; the current CI failure also occurs on main. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway chat.send parses uploads into managed media, prepares the selected sandbox workspace, and stages files before acknowledging the request. flowchart LR
A[Chat upload] --> B[Managed media parser]
B --> C[Chat attachment owner]
C --> D[Live workspace preparation]
D --> E[Media staging]
E --> F[Guarded filesystem write]
F --> G[Attachment facts and acknowledgement]
Technical reviewBest possible solution: Reuse the existing live preparation through staging while retaining current-authority checks and caller-owned disposal. Do we have a high-confidence way to reproduce the issue? Current-main source shows the chat owner preparing and releasing a workspace before staging prepares it again; the PR reports a baseline failure for the two-initialization case. Is this the best way to solve the issue? The patch uses the existing writer preparation rather than adding a cache or competing owner, and keeps other staging callers' acquisition behavior intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a466653c8c4a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +6, Tests +37, Other +373. Total +416 across 9 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 26, 2026, 4:58 PM ET / 20:58 UTC (Revision 2). |
Retain the live workspace preparation through pre-ACK media staging so sandboxed file uploads do not repeat workspace initialization and skill synchronization. Preserve mutation authority, cancellation, PDF fallback, and caller-owned disposal. Add work-count and revocation regressions plus a reproducible synthetic attachment benchmark.
ffda920 to
71a7fa2
Compare
|
Fixed the SSH fixture finding in The same follow-up fixes the benchmark fixture typing found by CI. Changed-file lint/format and the standalone benchmark typecheck pass; production code and the measured allocation calculation are unchanged. The PR body includes the corrections, measurement limits, and the independently reproduced inherited ACP assertion failures. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Inherited CI attribution for head The failed shard in run 40398880708 contains exactly two failures in
Both receive additional node scripts/run-vitest.mjs src/gateway/server-methods/chat.directive-tags.test.ts --maxWorkers=1 -t 'injects ACP system provenance|leaves ACP bridge user persistence'Each focused run reports 2 failed / 132 skipped. On the current CI head the failing shard reports 2 failed / 134 passed; the failure signatures are unchanged. This PR changes only the workspace-preparation mock in that test file, not ACP turn metadata or these assertions. The PR-caused benchmark type errors and SSH fixture failure from the first run are fixed: |
…claw#184985) * perf(gateway): avoid preparing chat attachment workspaces twice Retain the live workspace preparation through pre-ACK media staging so sandboxed file uploads do not repeat workspace initialization and skill synchronization. Preserve mutation authority, cancellation, PDF fallback, and caller-owned disposal. Add work-count and revocation regressions plus a reproducible synthetic attachment benchmark. * test(gateway): align attachment benchmark types and SSH fixture
What Problem This Solves
Sandboxed file uploads repeat workspace preparation before
chat.sendcan acknowledge the input. The first preparation was immediately released; media staging then repeated runtime classification, workspace initialization, and skill synchronization bookkeeping.User Impact
Prepare the attachment workspace once while preserving file bytes/order, current mutation authority, cancellation cleanup, pre-ACK errors, managed-PDF fallback, and SSH filesystem-bridge behavior. No protocol, UI, configuration, or storage-schema change.
Why This Change Was Made
The chat attachment owner now retains its existing live workspace preparation through staging. Staging borrows it and disposes only preparations it creates itself. This removes duplicate work without a cache or weaker validation. Runtime production delta: +6 lines, required to distinguish borrowed from locally owned disposal; the separate benchmark is tooling. Other staging callers still acquire their own preparation.
Evidence
7f394ea14e2f: one sandboxed upload initializes its workspace twice. Candidate initializes it once. Both global agent owners retain their own exact file bytes.pnpm tsgo:corepassed. PR CI supplies broad proof.CI follow-up
The first CI run found two PR-caused validation issues: the benchmark widened known fixture content to
unknown, and the SSH staging test still mocked the previous preparation helper. The follow-up preserves the fixture's inferred string types withsatisfiesand migrates the SSH mock to the retained preparation handle; production code and measured behavior are unchanged. All five SSH tests now pass; changed-file lint/format and a standalone benchmark typecheck pass. A redundant sample-count summary that depended on another benchmark’s ambient type augmentation was removed; the complete raw allocation profile remains available. The follow-up received a clean independent review.Two ACP provenance assertions in
chat.directive-tags.test.tsfail because their expected user turns omitmodelSelection. Both failures reproduce identically on the PR head and unchanged main9d52e3c5b18busing the same focused test command. These inherited expectations are separate from attachment staging; no unrelated source changes or CI reruns were used to hide them.The final CI run 40398880708 completed on
71a7fa2ff9bcde1fc1f1424c65f6afddf856b57b. Every selected non-aggregate job passed except the shard containing those two inherited ACP assertions; the aggregate gate remains red for that shard. All three PostgreSQL shards, typechecks, lint, source guards, attachment tests, and SSH staging passed. Hosted Codex review and the ClawSweeper re-review both report no actionable findings on this head. Landing uses the authorized inherited-failure exception, with baseline reproduction evidence.Measurement
Warm attachment preparation on isolated synthetic state, with no provider calls; two warm-up operations per selected workload precede measurement. Three 300-operation untraced paired comparisons of twelve 4 KiB text attachments; two 300-operation paired allocation passes; mixed 4.12 MiB PNG / 1.00 MiB PDF / twelve-file batches; counterbalanced order. The benchmark verifies original and staged SHA-256 values. CPU/latency measure preparation; sampled main-thread allocation and GC include request normalization, verification, and cleanup. Allocation passes are diagnostic and are not used to gate timing.
Allocation repeated closely: base 23.343/23.380 MiB and candidate 16.688/16.743 MiB. CPU and wall time are host-sensitive. The primary mean latency is neutral; its tail is near the adverse threshold, not a latency-win claim. The third untraced pair was predeclared after opposite-sign p95 deltas. No arm was excluded.
Short mixed samples appeared slower, but four matched identical-source A/A pairs produced many-file mean deltas of +45%, +58%, −26%, and +72%. The protocol was extended from 90 to 300 fixed operations per arm, with fresh AB/BA and four fresh A/A pairs, leaving natural GC and maintenance enabled.
Fresh longer A/A control deltas (many-file mean latency): +5.0%, -30.5%, +18.2%, +50.9%.
These are warm owner measurements, not cold-start, full Gateway ACK, or concurrent-turn measurements. The duplicate-work deletion uses focused owner proof; it makes no claim to remove an entire observed send delay. No load was sent to an operator Gateway. SSH still resolves its filesystem bridge separately.
Reproduce with the header commands in
scripts/perf/chat-send-attachments-measure.ts, using immutable baseline/candidate copies of the two owner files via--owner-dir, fresh--state-dirpaths,--workload many --iterations 300, a separate--allocationspass, and--workload mixed --iterations 300. JSON reports source SHA-256/load receipts, per-kind GC, sample counts, host load, RSS and heap.All arms: CPU, preparation latency, GC, event loop, memory, and host load
B = baseline, C = candidate; controls all load B. Allocation rows are traced diagnostics. Mixed latency below is the many-file subcase. Loop p99 values include their sample count; mixed per-case p95/p99 values have fewer samples and remain context. RSS/heap are end-of-arm snapshots, not retained-heap claims.
GC detail below is count / total ms / maximum pause ms. Major-GC percentiles remain context when fewer than 50 collections occur.