Repository navigation
feat(bridge): attach the context-composition snapshot to the context meter - #14
Conversation
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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: 4951add9fb
ℹ️ 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".
| "v4/conversation/contextComposition", | ||
| { sessionId: session.providerThreadId }, | ||
| 2000, | ||
| ), |
There was a problem hiding this comment.
Mark the optional composition query as read-only
If the composition query takes longer than two seconds, ZCodeClient.request() defaults its fourth argument to readOnly = false, so its timeout calls fail() and closes the shared ZCode process. The surrounding catch cannot undo that: an optional context-meter refresh can terminate an otherwise healthy session and trigger crash recovery instead of falling back to the plain meter. Pass the read-only flag so a slow composition read only drops the snapshot.
Useful? React with 👍 / 👎.
| const size = count(model.contextWindow) ?? fallback.size ?? null; | ||
| if (size === null || size === 0) return undefined; |
There was a problem hiding this comment.
Apply the selected reporting budget to the rich snapshot
When a user selects a budget variant such as test/model-256k for a native 1M-token model, finishTurn() passes the selected 256,000-token window, but this expression prefers the native window. Consequently, the same delta reports size: 256000 alongside snapshot.contextWindowTokens: 1000000; copying native freeTokens also makes the snapshot's free bucket exceed the selected budget. This contradicts the existing budget behavior covered in tests/core-features.test.ts. Apply the selected reporting window to the snapshot and recompute its free bucket against that window.
Useful? React with 👍 / 👎.
|
Review round 1 fixed (this branch now includes the rebased stage-10 head plus
Suite 298 green on the branch; stacked on #13. |
|
@codex review |
|
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". |
4951add to
caf1559
Compare
|
@codex review |
|
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". |
…meter After a turn settles, the bridge queries the CLI's v4/conversation/contextComposition (added upstream in v3.18.x; older CLIs answer method-not-found and keep the plain meter) and maps the measurement onto the contextWindow delta's rich snapshot: - native fine categories keep their identity with the projected bb kind - conversation content (messages, compact summary, reminders, user context) is used, prompt overhead and loaded tool schemas are reserved, deferred tool schemas are deferred - with per-entry token counts (wire caps: 50 entries, 200-char names); - the snapshot reports against the bridge-supplied window - the selected reporting budget (e.g. a 256k variant of a 1M model) - and the free bucket is recomputed from it, so the delta and its snapshot never disagree; - only request-phase measurements map; draft previews are dropped; - the query is read-only and bounded (2 s): a slow read drops only the snapshot, never the shared child process; a per-session revision guard drops a measurement that raced a newer settle; - usedTokens come from the ring-aligned providerContextTokens, and the snapshot can supply the meter numbers when the projection read has none. Roadmap stage 11; live 3.18.x verification is pending the local Desktop update (3.17.2 at implementation time).
|
Both findings closed in
Suite 298 green. |
caf1559 to
6ddd27e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
Stage 11 of the November upstream plan (
535c70c)bb's
contextWindowdelta accepts a richsnapshot(categories, entries,per-bucket tokens) that the plugin never sent — the audit's long-standing
gap. Upstream v3.18.x added
v4/conversation/contextComposition(revision-guarded, existing-only, names-and-sizes only), which is exactly
the missing source.
Change
contextSnapshot()(src/usage.ts, pure, unit-tested): maps a nativerequest-phase measurement onto bb's snapshot grammar — 11 fine categories
keep identity with the projected kind (
messages/compact_summary/reminders/meta_user_context→ used; prompt overhead + loaded toolschemas → reserved;
deferred_tool_schemas→ deferred), entries respectthe wire caps (≤50 per category, ≤200-char names), a synthetic
freebucket comes from the native
freeTokens; draft previews drop.finishTurn: one bounded (2 s) query aftersession/read; aper-session revision guard drops a measurement that raced a newer settle.
Older CLIs answer method-not-found → today's plain meter, unchanged.
providerContextTokens+ measured window) when the projection read hasnone —
Usage.contextprefers the projection and falls back.Verification
unusable drops), bridge integration (snapshot attached with mapped
categories; no snapshot on an old-CLI session).
typecheck,format:check.so the live happy path on 3.18.x is pending the app update; the degrade
path is what runs live today.
Docs: CHANGELOG, roadmap stage 11 done,
knowledge/log.md.Stack: based on #13 (stage 10); merge #13 first.