Repository navigation
fix(agents): preserve workspace rules in safeguard compaction - #168446
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. |
…ion-workspace-rules
|
Codex review: needs maintainer review before merge. What this changesThis PR makes safeguard compaction read configured AGENTS.md sections from the effective agent workspace and warn when rules cannot be included. Example: The Gateway runs from / while the agent workspace contains a configured section with QA-SAFEGUARD-WORKSPACE-RULE-168131.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a confirmed workspace handoff bug in both compaction paths, with no actionable code defects found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherEmbedded session preparation supplies workspace and configuration facts to the safeguard extension, which appends bounded workspace rules to the summary before session persistence. flowchart TD
A[Automatic session preparation] --> C[Extension factory]
B[Explicit compaction preparation] --> C
C --> D[Session scoped safeguard runtime]
D --> E[Bounded workspace reader]
E --> F[Summary finalization]
F --> G[Persisted compaction summary]
Technical reviewBest possible solution: Use the effective workspace throughout both compaction paths while retaining the existing opt-in, file boundaries, and summary limits. Do we have a high-confidence way to reproduce the issue? Current main shows both missing workspace arguments and the cwd fallback; the supplied baseline Gateway trace confirms the resulting missing persisted rules. Is this the best way to solve the issue? The patch repairs the missing facts at both producers, strengthens the internal contract, and preserves the existing reader safeguards without adding configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 240fa4ae59b3. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +191, Docs 0. Total +196 across 15 files. Added test files: 2. View PR surface stats
Review metrics
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 Reviewed October 10, 2026, 8:59 AM ET / 12:59 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
… (extracted hotfix) Extracted from #168446 (d7f014a): took only the workspaceDir plumbing. Manual compaction (compaction-session-execution.ts) and attempt session preparation (attempt-session-prepare.ts) now pass the effective workspace to buildEmbeddedExtensionFactories, and extensions.ts makes workspaceDir required. Without it the compaction safeguard defaults to process.cwd(), so service installs (Gateway cwd != workspace) lose AGENTS.md critical rules on compaction. Carried the attempt-session regression case and the required-field updates in existing tests (plus the branch-only compaction-safeguard.test.ts caller). Left out the compaction-workspace-context module extraction, the compact.hooks test-suite reshuffle, and docs: they are refactors with no behavior change for this bug. Extracted-from: d7f014a Co-authored-by: Peter Steinberger <[email protected]>
Release provenance: 89329f6 -> #168587 Release provenance: e6a9022 -> #168905 Release provenance: 15f3f12 -> #162266 Release provenance: 20805b8 -> #169430 Release provenance: 568fec8 -> #169102 Release provenance: 39dba6d -> #160440 Release provenance: 5df28c7 -> #168393 Release provenance: 10bcd8e -> #168164 Release provenance: dc5f1f5 -> #168446 Release provenance: 9f1e441 -> #168044 Release provenance: 5a235fc -> #168651
Fixes #168131
What Problem This Solves
Fixes missing workspace rules in safeguard compaction summaries when the Gateway starts outside the agent workspace.
User Impact
Configured AGENTS.md sections now survive automatic and explicit compaction using the effective agent workspace. Unreadable files and missing configured sections produce warnings. No configuration, protocol, schema, or migration changes are required.
Why This Change Was Made
Both session preparation paths already know the effective workspace, but omitted it when building safeguard extensions. The factory now requires that input, both callers supply it, and the reader no longer falls back to the Gateway's working directory. Bounded reads, alias checks, the legacy heading fallback, and available sections remain intact.
The workspace reader and its existing tests now have a small owner module, removing the old global test-only reader export. An existing safeguard test group moved to test support to keep grandfathered oversized files shrinking without dropping coverage.
Evidence
Both real caller regressions failed on main and passed after the repair. Reverting only the two production callers made both marker assertions fail again. The main baseline was also reproduced through a real isolated Gateway on a fresh AWS machine with the QA mock provider: compaction succeeded, but the persisted summary lacked both
<workspace-critical-rules>and the workspace marker.The fixed candidate passed the same real Gateway flow on a separate fresh AWS machine: the persisted summary contains
<workspace-critical-rules>, the configured heading, andQA-SAFEGUARD-WORKSPACE-RULE-168131despite a different process cwd. Both real compaction-summary HTTP requests succeeded, and the Gateway shut down cleanly.Local core types, the owning test-type groups (
agents-root,agents-other,agents-sessions), targeted oxlint, oxfmt, documentation configuration checks, and assertion/mock/timeout ratchets passed. Independent Codex autoreview was scoped-clean through P2.pnpm check:changedis blocked by an inherited main environment-variable budget failure: 456 names against 455. The same failure was reproduced using the unchanged main index withnode --import ./scripts/tsx.mjs scripts/check-env-var-count.mts --staged --base HEADbefore staging this patch.Proof commands, source identity, cost, and scope
Base refreshed with
git fetch origin main && git merge origin/mainbefore final proof:8b677154aef03278c14100a8dca7c629a8b1b4cb.Candidate:
c0e68ecb4710a7bf756dc7c80b4a9e6c6277071d; full Git tree:21c4d7219f1f3e800dde79aec2ef0ce63278a79a.Caller regressions:
The two complete caller files passed 109 tests (29.00 s Vitest, 56.48 s wrapper). New cases took 27 ms and 244 ms. The production-only negative control used the same command with
-t 'keeps .*workspace rules in .*compaction': both tests failed for the absent marker (8.28 s Vitest, 60.21 s wrapper including worker recompilation). Fixed bytes were restored and verified.After owner extraction, those two files plus
compaction-safeguard.test.tsandcompaction-workspace-context.test.tspassed 184 tests with--maxWorkers=1in 62.50 s wrapper wall time. The other affected factory/redaction tests also passed. CI is attached to the exact PR head: https://github.com/openclaw/openclaw/actions/runs/38052908605. Test-job timing remains pending while that run is in_progress.Remote baseline: AWS
cbx_f142786e0d1d,r7a.xlarge, 32 GiB, exact main45c7bc9e9ca9a838115d560ec13b67d287c3d2b4. The task launcher fetched the pinned source into a fresh checkout, installed frozen dependencies, built private QA, started the real Gateway in isolated state on an ephemeral port with cwd distinct from workspace, wrote a synthetic AGENTS.md section, and calledsessions.compactwithoutmaxLines. The persisted summary hadhasWorkspaceBlock=false,hasMarker=false; twocompaction-summaryprovider requests succeeded. Compaction took 1,873 ms; complete remote command 207.9 s. Gateway confirmed stopped, lease released and absent from the final lease inventory.Remote candidate: separate fresh AWS
cbx_00de3dcc73bc,r7a.xlarge, same memory class. The unpublished candidate was reconstructed from the pinned base plus a SHA-256-verified patch;git write-treematched the candidate tree above before execution. All 358 files / 4,530 tests passed across nine configurations. Complete module tests took 1,138 s; core types 72 s; owning test-type lane 288 s; private QA build 72 s; live Gateway proof 57 s. Aggregate remote command exit 0 (28m27.714s); live compaction itself took 1,927 ms. A shared AWS vCPU quota refusal cleared after one retry following a 4.5-minute wait.Exact credential-free baseline and candidate launch commands:
The standalone task launcher fetched the exact public base into its own checkout and verified the applied candidate, then ran these phases sequentially:
node scripts/run-vitest.mjsreceived the explicit 358-file list: every test undersrc/agents/agent-hooksandsrc/agents/embedded-agent-runner, plussrc/agents/embedded-agent-runner.extensions.test.tsand the sessionagent-session-compaction-boundary,agent-session-compaction, andagent-session-tool-result-redactiontest files. No extensions changed, so the extension type lane was not needed.Both live fixtures used
compaction.mode: "safeguard"andpostCompactionSections: ["Safeguard proof critical rules"]. The synthetic QA fixture disabled the separate semantic quality audit, while exercising the real Gateway, summary request, workspace read, and persisted transcript. Fixed summary excerpt:Both task Gateways confirmed stopped. Both AWS leases were explicitly released, and the final
crabbox list --provider aws --jsoninventory contains neither owned lease ID.Exact aggregate numstat versus the proof base: production +82/-77 (net +5), tests/support +585/-394, docs +1/-1. The production LOC exception is the small reader-module extraction required by the enforced oversized-file growth gate, alongside visible warnings; the initial inline fix was net zero. No checks, bounds, or assertions were weakened to meet the size target.
ClawSweeper's issue findings are addressed by both caller-to-summary regressions, the required workspace contract, removal of the cwd fallback, and live persisted-summary proof. No claim is made that mocks test an external model service; the live proof tests the real Gateway and storage flow against the deterministic QA provider.
Landing CI attribution
Reviewed landing head:
0e1996f50cb4a53054229daa7c03373a81ffdde7. It incorporates the main fix forprepared-model-runtime.scoped-refresh.test.tswithout changing this PR's product patch.Exact-head CI run 38053560800, attempt 1 completed with 48 successful jobs, 23 skipped jobs, and two failures:
checks-node-changed-compact-large-8plus its downstreamopenclaw/ci-gate. The sole root failure isserver-worker-placement-session-evidence.test.ts/keeps ordinary directory discovery failures independent from incognito evidence:expected [ 'unknown', 'unknown', 'unknown' ] to deeply equal [ 'unknown', 'current', 'absent' ].The latest scheduled main run independently reports the identical failure. This PR does not change that test or its placement/config-session/state/infra inputs. The inspected CI checkout is
9dbae401bfb66affc492dc0e9493f5421c279b8c, with baseline240fa4ae59b3016f9507f49cdd21658e6f56e161and the exact reviewed head as ordered parents. No CI jobs were cancelled;security-fastand the remaining selected checks passed. Landing uses the authorized native inherited-failure exception and retains the failed CI result.