Skip to content

agentHost: recheck Codex hook trust before the first turn - #336358

Draft
Dmitriy Vasyura (dmitrivMS) wants to merge 2 commits into
mainfrom
agents/root-cause-investigation-vscode-3840
Draft

Dmitriy Vasyura (dmitrivMS) wants to merge 2 commits into
mainfrom
agents/root-cause-investigation-vscode-3840

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes microsoft/vscode-engineering#3840

Summary

  • Track the hook trust applied when a fresh Codex thread starts.
  • Recheck before the first turn and reuse the existing pre-turn restart path if newly discovered hook hashes require a different grant.
  • Carry successful discovery into the replacement without a redundant lookup, revalidate workspace and hook-source trust before startup, and rediscover if the working directory changed.
  • Preserve existing grants on a failed recheck, log the failure, and keep Workspace Trust/revocation checks intact.
  • Add seven regression cases and document the fresh-workspace requirement. No timeout increase, quarantine, or persistent hook grants.

Root cause and evidence

In a fresh workspace, hooks/list can return no project hooks before thread/start establishes native project trust. The thread then starts without hooks.state, and a model turn can finish successfully without running the synchronous SessionStart marker hook. Incidental pre-turn restarts can mask this ordering problem.

The original failure in build 473136 took 30.450 seconds. Checkout logs confirm the failed attempt and existing passing retry both used d550ca3ed31712f730403f337ce7bcae62aadf1b; the retry is not evidence of a resolving change.

Reproduced with the locked Codex 0.153.0 SDK on main aa513800f750ab6a2edf90d45fa28bfe7e411749. Native controls returned zero hooks before startup and one afterward; restarting with the discovered hash produced the marker in 3/3 controls. The original integration assertions remain unchanged and pass with this fix.

Original provider-internal CI logs were not published, so the historical restart trigger is inferred; the failure mechanism and fix were reproduced locally. This does not claim a common cause for the other timeouts aggregated in the tracker.

Overlapping work

Searches of open VS Code hook, Codex, Workspace Trust, and exact-marker reports found no additional open issue that this patch can confidently close.

Validation

Windows, Electron 42.10.0, locked Codex 0.153.0:

  • Targeted transpilation and scoped TypeScript checking of changed modules/dependencies: passed.
  • scripts\test.bat --run src\vs\platform\agentHost\test\node\codex\codexCreateChat.test.ts: 98 passing.
  • scripts\test-integration.bat --run src\vs\platform\agentHost\test\node\providerIntegration\codexCustomizations.integrationTest.ts: 6 passing (five provider cases plus the harness check).
  • Repository hygiene on changed files and git diff --check: passed.

No full build, CI rerun, or Linux/macOS validation was performed.

Refresh the thread-scoped hook grant after native project trust becomes available. Reuse the existing pre-turn replacement path only when trust changes, and preserve existing grants when discovery fails. Cover late discovery, unchanged trust, lookup failures, and revocation.

Fixes microsoft/vscode-engineering#3840

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 16, 2026 00:56
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added vscode-build VS Code build process issues engineering VS Code - Build / issue tracking / etc. agent-host-codex labels Sep 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Replacement materialization can discard a successful recheck when its redundant hook lookup fails.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds a first-turn Codex hook-trust recheck to address cold-start hook discovery.

Changes:

  • Tracks applied hook trust and restarts when discovered hashes change.
  • Adds four regression cases covering discovery, failure, and revocation.
  • Documents fresh-workspace integration-test requirements.
File Description
codexAgent.ts Implements hook-trust tracking and rechecking.
codexCreateChat.test.ts Adds first-turn trust regression tests.
providerIntegration/​README.md Documents Codex hook test isolation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/platform/agentHost/node/codex/codexAgent.ts Outdated
Carry successful hook discovery into the replacement instead of repeating a lookup that can fail. Revalidate workspace and hook-source trust immediately before startup, and rediscover if the working directory changed. Cover the redundant lookup failure and trust/cwd changes in regression tests.

Addresses review feedback on #336358.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-host-codex engineering VS Code - Build / issue tracking / etc. vscode-build VS Code build process issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants