Skip to content

feat(llm): wire sideQuery onto ctx.llm capability seam (audit 1.1.2) - #173

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.2-ctx-seam-wire
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.2-ctx-seam-wire

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Audit §1.1.2: ctx.llm capability 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 onto ctx.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 through ctx.llm:

  • Builds a Ctx and passes it to modelSupportsStructuredOutputs(model, ctx) when both hold:
    1. output_format is in play (the structured-output beta decision point), AND
    2. provider is cloud (firstParty/foundry/bedrock/vertex/openai).
  • fusionMlx stays 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.
  • Lazy: ctx only built when output_format truthy AND provider non-MLX. The common no-output_format path allocates nothing.
  • Fail-open: try/catch → undefined ctx → old path on any factory error (no new failure mode).
  • Globals getCwd() + getSessionId() (both sync) supply cwd/sessionId without prop-drilling — sideQuery has 10 callers, all stateless classifiers.

Why sideQuery

sideQuery is async + stateless + self-contained + has model in scope. The other call sites (claude.ts:1593, api.ts:195) are deep in sync betasParams-build blocks — hoisting async createCtx there is invasive (Rule 3). sideQuery is the surgical target.

Byte-identical proof (per-provider)

Provider Old path ctx.llm path Result
firstParty 6-clause canonical-name list firstPartySupportsStructuredOutput — identical 6-clause list byte-identical
foundry name-list provider === "foundry" → true more-correct (capability-authoritative)
bedrock/vertex/openai false false byte-identical
fusionMlx false (blanket-deny) reads MLX keywords → may return true divergence → MLX gated to old path

MLX 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 from capability.test.ts (real adapter, env isolation):

  1. firstParty: 9 model ids, with-ctx == no-ctx (byte-identical loop)
  2. firstParty structured models (claude-sonnet-4-6/opus-4-6/haiku-4-5) → true
  3. firstParty non-structured (claude-sonnet-4) → false
  4. foundry: capability-authoritative → true
  5. bedrock/vertex/openai: byte-identical (both false)
  6. fusionMlx gate: sideQuery passes ctx=undefined → old path false (reference ctx would return true — divergence documented)
  7. seam guard: mismatched ctx.llm.modelId falls back to old path

Also fixed

Pre-existing typecheck error in viewedTaskSelector.test.ts (not introduced by this PR — fakes were as unknown as TaskState widened, .toBe() overload rejected the union). Re-typed teammateTask/localAgentTask fakes to narrowed InProcessTeammateTaskState/LocalAgentTaskState. Behavior unchanged, 10/10 still pass. Per repo rule: fix failing cases even if unrelated to own change.

Gates

  • bun run typecheck — 0 errors
  • bun 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 sideQuery output_config.format path, 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]

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]>
@dahai80
dahai80 merged commit 3e7279c into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.2-ctx-seam-wire branch August 28, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant