Skip to content

[codex] Preserve workspace metadata reuse for model refreshes#77554

Merged
steipete merged 1 commit intomainfrom
codex/workspace-metadata-reuse-model-paths
May 4, 2026
Merged

[codex] Preserve workspace metadata reuse for model refreshes#77554
steipete merged 1 commit intomainfrom
codex/workspace-metadata-reuse-model-paths

Conversation

@steipete
Copy link
Copy Markdown
Contributor

@steipete steipete commented May 4, 2026

Summary

  • Pass the resolved agent workspace into model-refresh paths that already have an explicit agent directory.
  • Cover BTW and PDF tool execution so workspace-scoped plugin metadata snapshots can be reused instead of falling back to cold metadata scans.
  • Add a changelog entry for the perf fix slice.

Root Cause

Some hot model setup paths called ensureOpenClawModelsJson(config, agentDir) after the runtime had already resolved the effective workspace. Because the workspace scope was dropped, getCurrentPluginMetadataSnapshot could reject the current workspace-scoped snapshot and force plugin metadata reconstruction.

This keeps the existing workspace-safety boundary: callers only pass workspaceDir when they already resolved it for the current run/tool.

Verification

  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/agents/pi-embedded-runner/run.ts src/agents/pi-embedded-runner/compact.ts src/agents/btw.ts src/agents/btw.test.ts src/agents/tools/pdf-tool.ts src/agents/tools/pdf-tool.test.ts
  • pnpm test src/agents/btw.test.ts src/agents/tools/pdf-tool.test.ts src/agents/models-config.write-serialization.test.ts src/plugins/current-plugin-metadata-snapshot.test.ts
  • pnpm test src/agents/pi-embedded-runner/compact.hooks.test.ts src/agents/pi-embedded-runner/run.before-agent-reply-cron.test.ts
  • Testbox pnpm check:changed passed: tbx_01kqtef6dp7ygbxbnexf721zg7
  • pnpm check:changelog-attributions

Refs #77519
Refs #77532

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 4, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 4, 2026

Codex review: needs changes before merge.

Summary
The PR threads a resolved workspaceDir into model-refresh calls for BTW, embedded run, compaction, and PDF model setup, adds focused test expectations, and updates the changelog.

Reproducibility: yes. from source inspection: /btw can be handled for params.agentId without a sessionKey, while the proposed runner-side workspace lookup falls back to the default agent in that case. A focused regression test can reproduce this by invoking /btw for a worker agent without a session key and asserting the worker workspace is used.

Next step before merge
A narrow PR-branch repair can fix the single BTW workspace routing bug and add focused coverage without a product decision.

Security
Cleared: The diff does not add dependencies, workflow changes, package-resolution changes, secret handling, or downloaded code execution; the workspace-routing defect is covered as a functional finding.

Review findings

  • [P2] Resolve BTW workspace from the command agent — src/agents/btw.ts:323-326
Review details

Best possible solution:

Thread a trusted agent id or already resolved workspace from handleBtwCommand into runBtwSideQuestion, keep the PDF and embedded-run workspace threading, and add non-default /btw regression coverage.

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

Yes, from source inspection: /btw can be handled for params.agentId without a sessionKey, while the proposed runner-side workspace lookup falls back to the default agent in that case. A focused regression test can reproduce this by invoking /btw for a worker agent without a session key and asserting the worker workspace is used.

Is this the best way to solve the issue?

No. Passing workspaceDir into model refreshes is the right direction, but the BTW part should reuse the command/session agent or pass the already resolved workspace instead of recomputing it from sessionKey alone.

Full review comments:

  • [P2] Resolve BTW workspace from the command agent — src/agents/btw.ts:323-326
    When /btw runs for a non-default agent without a sessionKey, commands-btw.ts already resolves agentDir from params.agentId, but this new workspace lookup only sees sessionKey and falls back to the default agent. That calls ensureOpenClawModelsJson for the worker agent directory with the default workspace, so workspace-scoped plugin metadata can be reused or written for the wrong agent. Pass the command/session agent id or already resolved workspace through to the runner.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.89

Acceptance criteria:

  • pnpm exec oxfmt --check --threads=1 src/auto-reply/reply/commands-btw.ts src/auto-reply/reply/commands-btw.test.ts src/agents/btw.ts src/agents/btw.test.ts
  • pnpm test src/auto-reply/reply/commands-btw.test.ts src/agents/btw.test.ts
  • pnpm test src/agents/tools/pdf-tool.test.ts src/agents/models-config.write-serialization.test.ts src/plugins/current-plugin-metadata-snapshot.test.ts src/agents/pi-embedded-runner/compact.hooks.test.ts src/agents/pi-embedded-runner/run.before-agent-reply-cron.test.ts

What I checked:

  • Protected label: The GitHub context lists the maintainer label, so this PR should not be closed by cleanup automation. (b81feddf64e3)
  • BTW command agent resolution: When no sessionKey is present, handleBtwCommand resolves sessionAgentId from params.agentId and then resolves that agent's directory before calling runBtwSideQuestion. (src/auto-reply/reply/commands-btw.ts:38, 43b5df729593)
  • Default fallback source: resolveSessionAgentId delegates to resolveSessionAgentIds; without an explicit agent id or parsed session key, that helper falls back to the default agent id. (src/agents/agent-scope.ts:50, 43b5df729593)
  • Workspace affects model snapshot reuse: ensureOpenClawModelsJson uses options.workspaceDir when asking getCurrentPluginMetadataSnapshot for the current plugin metadata snapshot, so passing the wrong workspace changes reuse eligibility and fingerprinting. (src/agents/models-config.ts:172, 43b5df729593)
  • Snapshot workspace guard: getCurrentPluginMetadataSnapshot rejects snapshots when the requested workspaceDir does not match the snapshot workspace. (src/plugins/current-plugin-metadata-snapshot.ts:83, 43b5df729593)
  • History sample: Blame and sampled log history point to Vincent Koc's recent plugin metadata/model config work and steipete's broader embedded-run/models refactors as the main routing candidates. (src/agents/btw.ts:229, 43b5df729593)

Likely related people:

  • Vincent Koc: Current-main blame for the central BTW, commands-btw, models-config, and current-plugin-metadata-snapshot lines points to commit daefb5e341 (fix(plugins): trust catalog package installs). (role: recent maintainer of plugin metadata/model refresh plumbing; confidence: high; commits: daefb5e3412f; files: src/agents/btw.ts, src/auto-reply/reply/commands-btw.ts, src/agents/models-config.ts)
  • steipete: Sampled history shows substantial prior work on embedded runner setup, compaction hooks, provider runtime, and models.json planning; the path shortlog also shows the largest contribution count across the sampled files. (role: adjacent embedded-run/models owner; confidence: medium; commits: c29b09874416, 749eb4efeadc, 5a98a1dbe274; files: src/agents/pi-embedded-runner/run.ts, src/agents/pi-embedded-runner/compact.ts, src/agents/models-config.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 43b5df729593.

@steipete steipete marked this pull request as ready for review May 4, 2026 21:59
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b81feddf64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/btw.ts
Comment on lines +324 to +328
const sessionAgentId = resolveSessionAgentId({
sessionKey: params.sessionKey,
config: params.cfg,
});
const workspaceDir = resolveAgentWorkspaceDir(params.cfg, sessionAgentId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve BTW workspace from the command agent

When /btw runs for a non-default agent without a sessionKey, commands-btw.ts already resolves agentDir from params.agentId, but this new workspace resolution only sees sessionKey and falls back to the default agent. In that scenario ensureOpenClawModelsJson is called for the non-default agent directory with the default agent's workspace, so workspace-scoped plugin model metadata can be reused or generated for the wrong workspace and written into the worker agent's models.json. Pass the command/session agent (or the already-resolved workspace) through instead of recomputing it from sessionKey alone.

Useful? React with 👍 / 👎.

@steipete steipete force-pushed the codex/workspace-metadata-reuse-model-paths branch from b81fedd to a0db1e7 Compare May 4, 2026 22:08
@steipete steipete merged commit a7263de into main May 4, 2026
109 checks passed
@steipete steipete deleted the codex/workspace-metadata-reuse-model-paths branch May 4, 2026 22:13
@steipete
Copy link
Copy Markdown
Contributor Author

steipete commented May 4, 2026

Landed.

  • Source SHA: a0db1e7
  • Merge commit: a7263de
  • Verification: PR CI green on the source SHA; Testbox pnpm check:changed passed on tbx_01kqtef6dp7ygbxbnexf721zg7; local targeted tests passed for BTW/PDF/models-config/plugin-metadata snapshot coverage.

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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant