Repository navigation
feat(llm): wire sideQuery onto ctx.llm capability seam (audit 1.1.2) - #173
Merged
Merged
Conversation
First real prod consumer for the ctx.llm capability seam (ar-plan PR #155/#157 landed it byte-identical-off with 0 prod consumers — 555 LOC dead scaffolding). Per audit 1.1.2 decision "wire 1 real consumer". sideQuery (stateless, async, self-contained) now builds a Ctx and passes it to modelSupportsStructuredOutputs when: - output_format is in play (structured-output beta decision), AND - provider is cloud (firstParty/foundry/bedrock/vertex/openai). fusionMlx stays on the old provider-if path: its capability reads MLX model keywords (qwen3/llama3/...) and would enable the beta for models the old path blanket-denied — a deliberate capability-authoritative divergence deferred until the MLX beta-header behavior is verified. Cloud path is byte-identical (firstParty 6-clause list matches betas.ts; foundry/3P both return false). Fail-open: ctx build error -> undefined ctx -> old path (no new failure mode). Lazy: ctx only built when output_format truthy AND provider non-MLX. Globals getCwd()/getSessionId() (sync) supply cwd/sessionId without prop-drilling (sideQuery has 10 callers, all classifiers, stateless). Test: src/__tests__/utils/sideQueryCtxSeam.test.ts (7 tests, 38 expect): - firstParty 9 model ids with-ctx == no-ctx (byte-identical loop) - firstParty structured models return true - firstParty non-structured returns false - foundry capability-authoritative returns true - bedrock/vertex/openai byte-identical (both false) - fusionMlx gate: sideQuery passes ctx=undefined -> old path false (reference ctx would return true — divergence documented) - seam guard: mismatched ctx.llm.modelId falls back to old path Also fix pre-existing typecheck error in viewedTaskSelector.test.ts (fakes re-typed to narrowed InProcessTeammateTaskState/LocalAgentTaskState — .toBe() overload rejected widened TaskState). Behavior unchanged, 10/10 still pass. Per repo rule: fix failing cases even if unrelated. Gates: typecheck 0 / 721 tests / lint net-zero 4601 / build:dev 3762. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audit §1.1.2:
ctx.llmcapability seam (ar-plan PR #155/#157) landed byte-identical-off with 0 prod consumers — 555 LOC of dead scaffolding. Audit verdict: delete OR wire consumers. Per the prior-session decision ("Wire 1 real consumer"), this PR migrates one real prod call site ontoctx.llm, converting dead scaffolding into a live seam with 1 validated consumer while preserving the ar-plan direction.What changed
src/utils/sideQuery.ts:147— the structured-output beta decision now flows throughctx.llm:Ctxand passes it tomodelSupportsStructuredOutputs(model, ctx)when both hold:output_formatis in play (the structured-output beta decision point), ANDfirstParty/foundry/bedrock/vertex/openai).fusionMlxstays on the old provider-if path — deliberately. Its capability reads MLX model keywords (qwen3/llama3/…) and would enable the beta for models the old path blanket-denied: a capability-authoritative divergence deferred until the MLX beta-header behavior is verified. MLX path = byte-identical to today.output_formattruthy AND provider non-MLX. The common no-output_formatpath allocates nothing.try/catch→undefinedctx → old path on any factory error (no new failure mode).getCwd()+getSessionId()(both sync) supplycwd/sessionIdwithout prop-drilling —sideQueryhas 10 callers, all stateless classifiers.Why sideQuery
sideQueryis async + stateless + self-contained + hasmodelin scope. The other call sites (claude.ts:1593,api.ts:195) are deep in sync betasParams-build blocks — hoisting asynccreateCtxthere is invasive (Rule 3).sideQueryis the surgical target.Byte-identical proof (per-provider)
firstPartySupportsStructuredOutput— identical 6-clause listprovider === "foundry"→ trueMLX divergence is deferred, not broken: MLX is excluded from the ctx migration so the risky path stays byte-identical. The seam is live for the common cloud case.
Test
src/__tests__/utils/sideQueryCtxSeam.test.ts(7 tests, 38 assertions) — pattern fromcapability.test.ts(real adapter, env isolation):firstParty: 9 model ids, with-ctx == no-ctx (byte-identical loop)firstPartystructured models (claude-sonnet-4-6/opus-4-6/haiku-4-5) → truefirstPartynon-structured (claude-sonnet-4) → falsefoundry: capability-authoritative → truebedrock/vertex/openai: byte-identical (both false)fusionMlxgate:sideQuerypassesctx=undefined→ old path false (reference ctx would return true — divergence documented)ctx.llm.modelIdfalls back to old pathAlso fixed
Pre-existing typecheck error in
viewedTaskSelector.test.ts(not introduced by this PR —fakeswereas unknown as TaskStatewidened,.toBe()overload rejected the union). Re-typedteammateTask/localAgentTaskfakes to narrowedInProcessTeammateTaskState/LocalAgentTaskState. Behavior unchanged, 10/10 still pass. Per repo rule: fix failing cases even if unrelated to own change.Gates
bun run typecheck— 0 errorsbun test src/__tests__/— 721 pass (714 baseline + 7 new)bun run lint— net-zero vs baseline 4601 (lint exits 1 = pre-existing baseline, NOT a regression)bun run build:dev— passes (3762 modules)Follow-up
MLX path divergence: verify MLX beta-header behavior on the
sideQueryoutput_config.formatpath, then flip the MLX gate to route through capability too (removes the last provider-conditional branch). Tracked under #170.Co-Authored-By: Claude Fable 5 [email protected]