Skip to content

improve: reduce workspace agent lookup work for large fleets - #147144

Merged
steipete merged 1 commit into
mainfrom
codex/perf-workspace-inference-roster-7006
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-workspace-inference-roster-7006

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #145679.

What Problem This Solves

Choosing an agent from a workspace path repeatedly scans configuration as the agent fleet grows. This adds synchronous work to callers such as TUI workspace selection and workspace-aware skill commands.

User Impact

Large fleets can resolve the same workspace-to-agent match with less roster work. Existing path handling, longest matching root, tie order, and visibility of later workspace edits remain unchanged.

Why This Change Was Made

Run the existing workspace search inside the existing synchronous roster-facts batch. The batch lasts for one lookup; each agent still uses the normal filesystem canonicalization and containment checks. No persistent cache or new invalidation policy is introduced.

Evidence

  • 178 tests passed across the workspace lookup, agent scope, roster-batch lifecycle, and TUI suites. Both new 64-agent regressions fail on the original work bound after their semantic assertions pass.
  • Complete results matched across 24 original/candidate cohorts and three lifecycle cases, covering entries/list configuration, inherited/explicit paths, existing/missing paths, empty rosters, edits, symlink retargeting, and nested batch failure recovery.
  • At 256 agents, instrumented roster reads fell from 33,152 to 512 for explicit workspaces and from 164,224 to 1,024 for inherited workspaces. Singleton reads were unchanged.
  • A fixed original/candidate/candidate/original comparison ran 16 uninstrumented calls per cohort. All 96 full result arrays and lifecycle values matched. At 256 agents with existing paths, mean elapsed time fell 33.0–68.1% and CPU fell 29.8–66.6%; both process pairs improved in each such cohort.
  • Fresh source review found no actionable issues across 30 supplied contexts. All four selected static checks passed: exact-file formatting and lint, production typing, and the complete owning agents-root test graph. Other test graphs and unrelated routed guards were not repeated.

Missing paths and small fleets had mixed results. At 256 agents, list/explicit/missing was 0.9% slower with 0.6% more CPU on average. At 64 agents, entries/explicit/missing was 3.1% slower with 5.8% more CPU, with both pairs worse. Singleton entries/inherited/existing was 14.8% slower with 10.8% more CPU; no singleton benefit is claimed.

These are two process observations per arm on synthetic Linux fixtures. Real filesystem canonicalization and containment remain inside the measured calls; imports, setup, result checks, and lifecycle checks are outside. A queued-immediate probe and retained return arrays can affect short windows and garbage collection. Process peak RSS ranged 188.6–189.5 MiB across the four processes; this does not establish retained-memory or whole-Gateway/TUI startup gains.

The timing, 178-test result, and original static proof above use fixed c1191cf5c9b29f617b765216b16ffa992a8bef09 source and its actual @openclaw/fs-safe 0.10.0 installation. Those measurements were not repeated on later main.

Integration on b076a15e510374bbc73750d0d58bcc4e4025648a preserves main's separately landed runtime-default/data-owner distinction from #146246 and the unchanged workspace batch wrapper. An isolated checkout with an ordinary frozen installation passed both focused suites: 34 tests covering the two large-roster lookup regressions and current owner-selection/inherited-workspace siblings. No test bounds were changed and no full build was repeated. The later patch-identical refreshed head passed exact-head CI; normal native prepare/merge gates remain required before landing.

The earlier hosted Control UI gzip failure was also present on main. Separately owned #147116 repaired main's baseline; this PR changes no UI budget or baseline. The subsequent d6ed2956 CI run passed before main's import overlap required the resolved integration above.

The subsequent 89af761b integration run failed only the inherited Workboard unawaited-close lint error and its aggregate gate. Separately owned #147203 fixed that error on main. This branch was then rebased to 201f11afefdb19a9c75e9d3542bf7425c80df7a7: the commit is patch-identical by range-diff, both changed file hashes and all 30 inspected owner/caller/test/doc contexts are unchanged. The 34-test source proof is reused; unrelated main package/script changes are covered by fresh exact-head hosted CI and native gates, not claimed as an identical installation. Previous failed CI and historical timing remain retained.

Exact refreshed head 9f8b7c1993406d81d75b915e5658602f7f82f100 passed CI run 34773626068, including the aggregate gate, production/test typing, lint and applicable tests. The current-head hosted source review reports no actionable findings. All four normal native source stages verified the same two changed file bytes and 30 inspected contexts; captured main 21de1eaf75db7f80cbc3114a451db244c07d9267 still lacks this batch wrapper.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 13, 2026 15:27
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 2:16 PM ET / 18:16 UTC (Revision 4).

ClawSweeper review

What this changes

Reuses agent-configuration facts during each workspace lookup to reduce repeated roster scans, with regression coverage for matching and subsequent configuration edits.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from current main. No actionable correctness or security findings remain, and the previous review's changed files are unchanged.

Priority: P2
Reviewed head: 9f8b7c1993406d81d75b915e5658602f7f82f100

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful owner-level evidence, disclosed measurement limits, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded Linux comparisons exercise the production workspace resolver with real filesystem canonicalization and containment, showing equal selections and reduced large-roster work; later integration coverage and verified unchanged reviewed files support reuse without claiming current-head timing or whole-application gains.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Linux comparisons exercise the production workspace resolver with real filesystem canonicalization and containment, showing equal selections and reduced large-roster work; later integration coverage and verified unchanged reviewed files support reuse without claiming current-head timing or whole-application gains.
Evidence reviewed 8 items Introduced change and lifecycle: The pinned merge-base-to-head patch wraps the existing synchronous lookup in the existing roster batch. The batch keys facts by config identity and restores its parent in finally; canonicalization, containment, longest-match selection, and tie order remain intact.
Still necessary on main and latest release: Inspected fetched main and the supplied latest-release commit through local source and GitHub contents respectively; both retain the unbatched workspace loop. No supplied merged related PR implements this optimization.
Regression coverage: Both 64-agent representations assert longest-root selection, first-match ties, visibility of later workspace edits, unrelated-path rejection, and bounded roster reads. Existing workspace tests cover Unicode and symlink behavior; session-utils performance tests cover nested batch failure restoration and freshness after yielding. Tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

Workspace inference maps a directory to its configured agent for TUI startup and workspace-aware skills commands. It canonicalizes paths and selects the longest containing workspace, preserving roster order for ties.

flowchart LR
  A[Current directory] --> C[Canonicalize query path]
  B[Agent configuration] --> D[Lookup-scoped roster facts]
  D --> E[Resolve and canonicalize workspaces]
  C --> F[Choose longest containing workspace]
  E --> F
  F --> G[Selected agent or no match]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +57. Total +60 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 16 13 +3
Tests 1 57 0 +57
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 73 13 +60

Review metrics

None.

Technical review

Best possible solution:

Keep roster reuse scoped to the synchronous lookup while preserving fresh filesystem checks and configuration visibility between calls.

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

Yes, source establishes repeated roster traversal in the current unbatched loop, and the supplied original/candidate measurements exercise that path; this review did not execute it.

Is this the best way to solve the issue?

Yes, using the existing synchronous batch is a narrow solution that avoids a second cache or a new invalidation policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 83b9a532ef4c.

Labels

Label justifications:

  • P2: Reduces synchronous workspace-selection work for large fleets without changing user-facing contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded Linux comparisons exercise the production workspace resolver with real filesystem canonicalization and containment, showing equal selections and reduced large-roster work; later integration coverage and verified unchanged reviewed files support reuse without claiming current-head timing or whole-application gains.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Linux comparisons exercise the production workspace resolver with real filesystem canonicalization and containment, showing equal selections and reduced large-roster work; later integration coverage and verified unchanged reviewed files support reuse without claiming current-head timing or whole-application gains.

Evidence

What I checked:

  • Introduced change and lifecycle: The pinned merge-base-to-head patch wraps the existing synchronous lookup in the existing roster batch. The batch keys facts by config identity and restores its parent in finally; canonicalization, containment, longest-match selection, and tie order remain intact. (src/agents/agent-scope.ts:711, 9f8b7c199340)
  • Still necessary on main and latest release: Inspected fetched main and the supplied latest-release commit through local source and GitHub contents respectively; both retain the unbatched workspace loop. No supplied merged related PR implements this optimization. (src/agents/agent-scope.ts, 83b9a532ef4c)
  • Regression coverage: Both 64-agent representations assert longest-root selection, first-match ties, visibility of later workspace edits, unrelated-path rejection, and bounded roster reads. Existing workspace tests cover Unicode and symlink behavior; session-utils performance tests cover nested batch failure restoration and freshness after yielding. Tests were inspected, not executed during this read-only review. (src/agents/agent-scope.workspace-inference.test.ts:11, 9f8b7c199340)
  • Previous-review continuity: GitHub contents at previously reviewed 89af761 match current blobs exactly: agent-scope.ts is 6e2aa1ee752303c58d370afbc0e7ddb53513ba3d and the regression file is 5aa3ad4b2cd34723caa62927392f38dc7cd36219. GitHub verification recovered the comparison after local historical-object access failed. The supplied completed review has no findings or published rank-up moves. (src/agents/agent-scope.ts, 9f8b7c199340)
  • Recorded production-owner measurements: The captured PR body reports real filesystem canonicalization and containment in synthetic Linux original/candidate runs: all 96 result arrays matched; 256-agent existing-path cohorts improved mean elapsed time by 33.0–68.1%. It discloses adverse singleton/missing-path cohorts, process RSS of 188.6–189.5 MiB, the historical c1191cf baseline, and 34 later integration tests. These establish bounded lookup evidence, not whole-Gateway or retained-memory gains. Prepared media belongs to the unrelated sidebar PR and is not lookup proof.
  • Existing caller contract: Skills commands document explicit agent selection followed by current-directory workspace inference; skills-cli.ts and TUI startup invoke this resolver. The optimization changes neither caller precedence nor persisted configuration. Public docs: docs/cli/skills.md. (docs/cli/skills.md:97, 9f8b7c199340)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-13T15:35:38.644Z sha 2891ca407b468eba7fc5fef9404471fc61a4faa5 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-13T16:34:18.804Z sha d6ed295 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-13T17:15:34.510Z sha 89af761 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf-workspace-inference-roster-7006 branch from 2891ca4 to d6ed295 Compare September 13, 2026 16:22
@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 Sep 13, 2026
@steipete
steipete force-pushed the codex/perf-workspace-inference-roster-7006 branch from d6ed295 to 89af761 Compare September 13, 2026 17:08
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 13, 2026
@steipete
steipete force-pushed the codex/perf-workspace-inference-roster-7006 branch from 89af761 to 9f8b7c1 Compare September 13, 2026 18:06
@steipete
steipete merged commit 47cb143 into main Sep 13, 2026
191 of 192 checks passed
@steipete
steipete deleted the codex/perf-workspace-inference-roster-7006 branch September 13, 2026 18:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: improve: reduce workspace agent lookup work for large fleets This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '28887b564210326174413d0d8ade72b38268d5f3': (1827 commits)
  fix(qa): bind coverage IDs to producer assertions (#144000)
  fix(linux): explain FreeBSD desktop setup prerequisites (#147211)
  fix(memory): split embedding batches rejected for an input array item cap (#139541)
  test: isolate timing metadata persistence from inherited settings (#147112)
  refactor(status): retire test-only helper publication (#147071)
  improve: reduce workspace agent lookup work for large fleets (#147144)
  refactor(macos): share connect credential selection (#144214)
  fix(plugins): restore Slack onboarding after core updates (#147109)
  refactor: share ANSI compatibility matching (#146998)
  fix(test): settle Models catalog before picker open (#147215)
  test(ui): reuse panel tab drag fixture (#147250)
  fix(install): use system Node for FreeBSD CLI setup (#147204)
  fix(cli): explain MCP probes with no enabled servers (#147216)
  docs: require UI screenshots in chat and PR (#147263)
  docs(skills): clarify remote gog OAuth setup for Gateway hosts (#145945)
  test: replace idle account catalog waits with synchronization (#147228)
  feat(qa): preserve maturity decision context (#147219)
  feat(macos): clarify agent activity in native chat (#147197)
  fix(runtime): complete Bun compatibility follow-ups (#147085)
  fix(ui): release closed chat panes after queued updates (#147240)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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