Repository navigation
perf(chatd): read fork per-chat facts once per generation step - #350
Conversation
buildTurnEnvironment now installs per-step facts on its context and seals them when it returns. While they are live, the fork hooks share one read of the chat_subagents rows, the chat's worktree, the organization's subagent limits and the chat's enabled plugin packs. Tool calls, spawn and admission run after the step is built and keep reading live, inside their transactions. Closes #299
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7648182aaa
ℹ️ 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".
@codex review The ARCHITECTURE.md paragraph is written in full on purpose: the maintainer's brief for #299 overrides the AGENTS.md TODO rule for this PR. Please review the code changes. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7648182aaa
ℹ️ 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".
…or lookup The project and ancestor helpers report a failed lookup only by logging it, so pack enablement now watches its logger for a warning and keeps the packs for the step only when none was logged.
@codex review The ARCHITECTURE.md paragraph is written in full on purpose: the maintainer's brief for #299 overrides the AGENTS.md TODO rule for this PR. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ment explicitly Replace the logger sink that detected failed lookups with returned errors. The ancestor walk returns its error through walkAncestorChatIDs, and pack enablement resolves the chat project with packProjectID, a fork-side copy of resolveUsableChatProjectID that returns a failed lookup. Add a test where only the project or ancestor lookup fails while the pack lookups succeed.
@codex review Head ea4ebe9 replaces the logger sink that pack enablement used to detect failed project and ancestor lookups with returned errors (walkAncestorChatIDs, packProjectID), and adds a test where only those lookups fail. ARCHITECTURE.md is written in full per the issue brief, which overrides the TODO rule. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
@codex review Head ba67e4b adds a parity test that runs packProjectID and the upstream resolveUsableChatProjectID over the same cases and requires the same project. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged at head Gates on this exact head:
Not exercised: a live chat run on the deployed server with the fork experiments on. The per-step cache is checked by unit tests only. |
Closes #299
What changed
buildTurnEnvironmentinstalls per-step facts on its context (fork_step_facts.go) and seals them when it returns. While they are live, the fork hooks of the step read each per-chat fact once:chatd.chat_subagentsrow of the chat and of each ancestor the worktree walk visits, shared bychatWorktree, the depth check ofsubagentCanSpawn(stepSubagentDepth) andcustomAgentToolPolicyOfChat;forkWorktreeAgentandwithForkWorktreeBinding;subagentCanSpawnand thespawn_agentdescription (stepSubagentLimits);materializePluginPacksand everyfilterPackResourcescall of the step.The upstream file gets one hook line in
turn_environment.go.Which value wins
The value read at the first lookup in a step wins for the rest of that step. The next step reads the new value. A failed lookup is not kept, and pack enablement is kept only when every pack lookup succeeded. Facts of another chat, and every read outside
buildTurnEnvironment, read live. Tool calls, spawn and capacity admission run after the environment is built, when the facts are sealed, sosubagentDepthandsubagentLimitskeep reading inside the spawn and admission transactions. Every hook reads with the step's context, so dbauthz checks are unchanged.TestForkStepFactsFirstReadWinscovers this rule.ARCHITECTURE.md gets a "Fork step facts" paragraph next to the "Fork context" note.
Findings from the issue
Checked on main at b4340bd:
ANY($1)queries, async pack materialization, thetokenBudgetChatEligibleread insyncForkContext, pack cleanup'senabledPacksfor other chats, and the upstreamListChatContextResourcesByChatIDreads.Store calls of one step
TestForkStepFactsReadOncecounts store calls throughdbmetricsfor the second step of a depth-2 shared subagent under a worktree child, with a tool policy and two packs enabled on the root.On main the test fails with
GetChatSubagentByChatID: expected 2, actual 6.Tests
go test ./coderd/x/chatd/... -count=1 -v: every package ok, 6276 passed, 0 failed, 4 skipped (provider round trip tests that need keys).go test ./coderd/x/chatd/ -run 'TestForkStepFacts|Isolation|Worktree|ToolPolicy|NestedSubagent|SpawnAgent|PluginPack|Pack' -count=1: ok.golangci-lint run --fix=false --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/: 0 issues.paralleltestctxandintxcheckon./coderd/x/chatd/: clean.Not verified: a live server run with real subagents.