Skip to content

fix: captureModel omitted inherits the session's model (#139) - #270

Merged
abogartz merged 1 commit into
mainfrom
fix-issue-139-inherit-session-model
Nov 3, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix-issue-139-inherit-session-model

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 3, 2026

Copy link
Copy Markdown

Closes #139

What

autoCapture: true with no captureModel now inherits the session's model instead of disabling. Resolution order: explicit captureModel option → the Model.Ref the session.context hook last carried for that session → ctx.model.default.get() → only then skip (warn once, reason=no_model on the refusal evidence line). An explicit but malformed captureModel keeps today's fail-closed setup behaviour. Every capture evidence line (auto_capture_*, auto_capture_refused/_partial, capture_lag) now carries model= so cost is attributable to a named model. autoCapture default off is unchanged.

Requirements taken from comments (not the body)

Acceptance evidence

Red-first, measured:

  • Red at merge-base 2d2fce7: the acceptance scenario (autoCapture on, no captureModel, fake host whose session.context carries {providerID:"fake",id:"session-model"}) fails with expect(subscribeCalls).toBe(2) → Received 1 — the subscription is never registered, exactly the stated disable.
  • Green on this branch: same scenario passes; generate.calls[0].model equals {providerID:"fake", id:"session-model"}.
  • New describe("capture model inheritance (#139)") in test/capture.test.ts: session-ref inheritance, host-default fallback, reason=no_model skip with zero model calls when both sources are empty, explicit option wins over the session ref, and model=fake/session-model on the auto_capture_promoted and capture_lag lines. Plus a heartbeat test: omitted captureModel → capture=on; explicit malformed → capture=invalid_model (unchanged).

Commands run (measured, Bun 1.4.3, macOS)

  • bun run typecheck — exit 0
  • bun run lint — exit 0; 503 warnings, identical to main baseline (measured on stashed tree: 503; zero delta)
  • bun run test — 924 pass / 19 skip / 0 fail (six consecutive clean runs; the very first run after bun install showed 1 failure whose name I did not capture and which did not reproduce in six subsequent runs — consistent with the documented cold-start timing flakes, CI re-verifies)
  • bun run test:e2e — 30 pass / 0 fail
  • bun test test/capture.test.ts test/capture-compaction.test.ts test/capture-sid-race.test.ts — 54 pass / 0 fail

Deliberately not changed

  • autoCapture default off; the zero-token default is untouched (criterion 3).
  • Invalid explicit captureModel still warns once at setup and skips registering the subscription — no silent substitution of a different model than the user typed.
  • The #152 no-workspace refusal still precedes the model call (model resolution itself is token-free and runs first so the refusal line can carry model=).
  • The compaction hook does not record into the session-model registry; inheritance reads the session.context ref per the ticket's fix text.
  • No changes to .github/workflows, labels beyond fix:*, or the issue body.

autoCapture:true is already the explicit opt-in; requiring a second
config key was a syntax tax whose failure mode was a silent disable.
An omitted captureModel now resolves per capture: the ref the
session.context hook last carried, else ctx.model.default.get(), and
only when both are missing does the pass skip (warn once, reason
no_model in evidence). An explicit invalid captureModel keeps the
fail-closed setup behaviour. Every capture evidence line now carries
model= so cost is attributable to a named model. autoCapture stays
default off.
@ocsi-triager ocsi-triager Bot added the review:requested Human-admitted for autonomous review by ocsi-reviewer label Nov 3, 2026

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Head reviewed: 118ef00e619dcbc1fae7df79e7f1a47a676e309a

Contract: #139 (authored by abogartz, trusted). Spec anchor 3ae9e1424330770a recomputed and equal to the frozen anchor comment — spec unchanged.

Acceptance, verbatim: "Red-first: autoCapture: true with no captureModel, against a fake host whose session.context carries a model ref, must fire a capture pass with that ref. Red on main today, where it disables instead."

Per-criterion evidence (measured at this head, not from the PR body):

  1. "Omitted captureModel resolves to the per-session ref last seen on session.context; else ctx.model.default.get(); only if both are missing warn and disable." — Resolution chain at src/capture/runtime.ts:178 (modelRef ?? sessionModel(sid) ?? hostDefault()); ref recorded in the session.context hook at src/events.ts:115; warn-once + skip at src/capture/runtime.ts:191-198 with reason=no_model on the refusal line. Tests capture model inheritance (#139) cover all four branches (inherit, host default, both-missing skip, explicit wins) — green.
  2. "Record model= on every capture evidence line" — auto_capture_refused (no-workspace) runtime.ts:186; auto_capture_partial/auto_capture_refused runtime.ts:242; the per-candidate outcome line incl. auto_capture_promoted runtime.ts:260; capture_lag via new optional model param src/evidence/record.ts:155. Test asserts model=fake/session-model on both the promoted and the lag line — green. The reason=no_model line carries no model= by definition (nothing resolved); acceptable.
  3. "Keep autoCapture default off" — no diff touches the default; existing default-OFF tests still green; heartbeat test armed with NO captureModel: capture=on green.

Red-first differential (verified myself at merge-base 2d2fce7): copied only this PR's test files onto the base tree (src untouched, one test-side no-op shim for the not-yet-existing resetSessionModels export): 5 fail. The acceptance test fails with the stated reason — autoCapture is on but captureModel "" is invalid (expected "provider/id"); auto-capture disabled. and subscribeCalls never reaches 2; heartbeat reads invalid_model where on is expected. At head: bun test test/capture.test.ts 41 pass / 0 fail. Differential holds: fixed side clean, broken side fails for the stated reason.

Commands run (Bun, macOS):

  • bun run typecheck — exit 0
  • bun run lint — exit 0, 503 warnings = main baseline
  • bun run test — 924 pass / 19 skip / 0 fail
  • bun run test:e2e — 30 pass / 0 fail (src/ changed)

Tests review: additive only (+102/−3 in test/capture.test.ts, −3 lines are header comment + import line; test/harness.ts +14/−2 adds the model.default.get fake and threads model through the context-hook replay). No deleted assertion, no .skip, no widened tolerance.

Findings:

  • P0: none.
  • P1: none.
  • nit: src/capture/session-model.ts:31-34 eviction is insertion-order FIFO, not LRU — a long-lived session's ref can be evicted while still active after 2000 distinct sessions; the capture then falls back to the host default. Bounded and harmless (fallback exists); the cap comment declares the rule. No action needed.

Final-gate re-check (verbatim, at filing time):

{"headRefOid":"118ef00e619dcbc1fae7df79e7f1a47a676e309a"}
[{"bucket":"pass","name":"test-windows"},{"bucket":"pass","name":"lint"},{"bucket":"pass","name":"test"},{"bucket":"pass","name":"smoke"}]

Human merges.

@abogartz
abogartz merged commit f43c146 into main Nov 3, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the fix-issue-139-inherit-session-model branch November 19, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released review:requested Human-admitted for autonomous review by ocsi-reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

captureModel should default to the session's model — event.model is already delivered to every hook and never read

1 participant