Skip to content

feat: context manager#259

Merged
sergiofilhowz merged 4 commits into
mainfrom
feat/context-manager
Jun 15, 2026
Merged

feat: context manager#259
sergiofilhowz merged 4 commits into
mainfrom
feat/context-manager

Conversation

@sergiofilhowz

@sergiofilhowz sergiofilhowz commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Add context-manager worker

Implements the context-manager Rust binary worker from
tech-specs/2026-06-agentic/context-manager.md: turns a raw conversation
history plus a target model into a model-ready context (system prompt +
budgeted messages) via four context::* functions.

Functions

  • context::assemble — count → prune → compact → assemble, fit to the model's usable budget
  • context::compact — summarise the head, keep a recent tail verbatim (ok | busy | empty | overflow)
  • context::prune — replace verbose function outputs with [output pruned: was ~N tokens] placeholders
  • context::count_tokens — estimate messages + tools + system prompt vs a model

Design

  • Ports-and-adapters: pure logic in src/core/ (budget math, chars/4 estimator behind a trait, prune walk, turn-boundary tail selection, summary templating, lease protocol) behind ModelResolver / Summarizer / LeaseStore / Clock traits, with production adapters for router::models::get, router::chat (stream channel), and state::update-backed compaction leases.
  • All request/response/wire types derive schemars::JsonSchema; schemas are generated from the structs and snapshotted as golden files.
  • Storage-agnostic per spec; llm-router is a soft dependency (token counting and pruning work standalone, summarisation/limit-resolution degrade cleanly when absent).
  • Hardening beyond the TS prior art: tail selection never cuts between a function_call and its result; custom messages are excluded from the model-facing list and its token count.

Tests

  • 79 BDD scenarios / 713 steps across 10 feature files — each scenario carries a # Prevents: comment naming the failure it guards. Pure scenarios run production handlers over deterministic fakes; 6 @engine scenarios validated against a live engine (real state::* lease cycle, router-absent degraded modes).
  • 57 unit tests, golden wire-schema snapshots (UPDATE_GOLDENS=1 to regenerate), --manifest contract test, and a subprocess end-to-end test.
  • cargo fmt --check, cargo clippy -D warnings, and cargo test --all-features all pass.

Wiring

  • Root README.md Modules row; create-tag.yml options + release.yml tag pattern; consumer README.md.

Out of scope

  • Migrating harness off its embedded context-compaction module onto this worker (separate follow-up).

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced context-manager worker with four core functions: token counting, function-result pruning, and history compaction via LLM summarization. All operations are stateless and storage-agnostic.
    • Refactored context-compaction as a thin wrapper that delegates to context-manager for model-ready context assembly.
  • Documentation

    • Added comprehensive architecture and integration guides.
    • Updated binary worker and onboarding documentation with naming conventions.
  • Tests

    • Added extensive BDD test suite covering assembly, compaction, pruning, and token counting scenarios with both in-process and engine round-trip validation.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
workers Ready Ready Preview, Comment Jun 15, 2026 8:49pm

Request Review

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

skill-check — worker

0 verified, 20 skipped (no docs/).

Layer Result
structure
vale
ai
render

Four for four. Nicely done.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds the Rust context-manager worker with four context::* functions, filesystem leases, router-backed summarization, configuration and schema support, extensive tests and docs, and migrates harness compaction and assistant-streaming flows to use the new worker.

Changes

Context manager rollout

Layer / File(s) Summary
Worker package, APIs, and published surface
.github/workflows/*, README.md, context-manager/Cargo.toml, context-manager/README.md, context-manager/iii.worker.yaml, context-manager/architecture/*, context-manager/tests/golden/schemas/*, docs/sops/*
Adds the new worker package, release/tag wiring, public docs, architecture references, and emitted JSON-schema surface for context::assemble, context::compact, context::prune, and context::count-tokens.
Context manager runtime and handlers
context-manager/src/adapters/*, context-manager/src/config*.rs, context-manager/src/core/*, context-manager/src/error.rs, context-manager/src/functions/*, context-manager/src/main.rs, context-manager/src/manifest.rs, context-manager/src/ports.rs, context-manager/src/types.rs, context-manager/config.yaml
Implements model resolution, token estimation, pruning, compaction, leases, configuration reload, manifest output, and the four handler entrypoints plus worker boot wiring.
BDD, integration, and schema validation
context-manager/tests/*
Adds Cucumber features, world/step helpers, fakes, engine registration helpers, integration coverage, manifest/schema tests, and golden-file support for the new worker behavior.
Harness compaction wrapper and orchestrator migration
harness/src/context-compaction/*, harness/src/runtime/compaction.ts, harness/src/runtime/session.ts, harness/src/turn-orchestrator/..., harness/tests/..., console/..., harness/docs/workers/*, harness/iii.worker.yaml
Replaces the old harness compaction implementation with a thin context-compaction::compact_session wrapper over context::compact, rewrites streaming context assembly to use context::assemble, persists compaction bookkeeping, and removes turn-end compaction wake behavior.
Policy and callable naming updates
iii-permissions.yaml, docs/sops/*
Denies context::assemble and context::compact by default for in-run agents and documents kebab-case naming rules for functions and triggers.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • iii-hq/workers#140: Introduced the earlier context-compaction worker that this PR replaces with a thin wrapper over context-manager.
  • iii-hq/workers#251: Related session-manager migration work overlaps with the new tail_start_entry_id compaction bookkeeping path.
  • iii-hq/workers#110: Also updates GitHub release and tag workflow patterns for worker publishing.

Poem

🐇 I packed a context satchel tight,
with tokens counted through the night.
I pruned the tools, compacted lore,
then left the transcript just as before.
Now wrappers hop and summaries sing,
while little lease keys guard the ring.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/context-manager

@coderabbitai coderabbitai 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.

Actionable comments posted: 7

🧹 Nitpick comments (1)
context-manager/Cargo.toml (1)

37-45: 💤 Low value

Redundant dev-dependencies already present in [dependencies].

serde_json, uuid, and tokio are already declared in [dependencies] (lines 21, 32, 19). Listing them again in [dev-dependencies] is unnecessary — Cargo merges features, but the duplication adds maintenance overhead.

♻️ Suggested cleanup
 [dev-dependencies]
-serde_json = "1"
 tempfile = "3"
 which = "8"
 # BDD test runner. Drives Gherkin .feature files under tests/features/.
 cucumber = "0.22"
 futures = "0.3"
-uuid = { version = "1", features = ["v4"] }
-tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "signal", "time"] }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@context-manager/Cargo.toml` around lines 37 - 45, Remove the duplicate
dependency declarations from the dev-dependencies section in Cargo.toml. The
dependencies serde_json, uuid, and tokio are already present in the main
dependencies section and do not need to be redeclared. Delete the lines
containing these three packages from the dev-dependencies block to eliminate
maintenance overhead, as Cargo will automatically make them available for dev
targets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@context-manager/src/core/lease.rs`:
- Around line 59-74: The lease acquisition and release logic uses non-atomic
multi-step operations (swap followed by set restore, and get followed by
set(None) clear) that allow race conditions where a newer lease holder can be
overwritten by an older path. Add an atomic compare-by-nonce operation to the
LeaseStore interface (such as clear_if_nonce or a similar CAS variant) that
atomically checks the nonce before modifying or clearing the lease. Replace the
two-step restore pattern in the acquire function (the swap followed by the set
call when is_active is true) with a single atomic operation that compares the
nonce before restoring. Similarly, replace the two-step clear pattern in the
release function (around lines 80-84) with the same atomic operation to ensure
mutual exclusion is preserved under contention.

In `@context-manager/src/core/prune.rs`:
- Around line 112-124: The pruned_tokens calculation on line 112 sums only the
original tokens being removed but fails to account for the tokens consumed by
the replacement placeholder text. This causes token savings to be overestimated
and can bypass the min_free_tokens check when actual net savings are lower. Fix
this by calculating the net token savings: for each item in the queue, determine
how many tokens the placeholder function will consume and subtract that from the
original token count. Update the pruned_tokens calculation to reflect this net
difference, ensuring the min_free_tokens comparison on line 113 validates actual
savings rather than gross removal amounts.

In `@context-manager/src/functions/count_tokens.rs`:
- Around line 18-20: The messages field is declared as Option<Vec<AgentMessage>>
in the struct definitions across multiple files, making it optional in the JSON
schema, but all request handlers require it at runtime via ok_or_else() checks.
Remove the Option wrapper from the messages field type definition in
CountTokensRequest (context-manager/src/functions/count_tokens.rs around line
20), CompactRequest (context-manager/src/functions/compact.rs around line 46),
PruneRequest (context-manager/src/functions/prune.rs around line 35), and
AssembleRequest (context-manager/src/functions/assemble.rs around line 62) to
make messages a required field that matches the runtime validation expectations
and aligns the JSON schema with actual handler behavior.

In `@context-manager/src/types.rs`:
- Around line 187-197: The `has_function_result_block` method's documentation
claims it recursively checks for `function_result` wrappers, but the `scan`
helper function only inspects the top-level blocks returned by `self.content()`
and does not recurse into the `content` field of nested
`ContentBlock::FunctionResult` blocks. Either update the doc comment to clarify
that only top-level blocks are checked (if deep nesting is not expected in
practice), or modify the `scan` helper function to recursively examine the
`content` field of any `FunctionResult` blocks encountered to ensure all nested
`FunctionResult` blocks are detected.

In `@context-manager/tests/common/engine.rs`:
- Around line 37-41: The match statement in the probe loop is incorrectly
retrying on all non-NotConnected errors by using a catch-all arm that continues
to the next iteration. This causes transient errors (like engine::workers::list
being unavailable) to eventually result in false test skips. Fix this by
changing the catch-all error arm at line 40 from continuing to the next
iteration to instead returning Some(iii), treating non-NotConnected errors as
"connected enough" for test registration. Only Err(IIIError::NotConnected)
should trigger a retry via continue; all other errors should be treated as
successful connection.

In `@context-manager/tests/integration.rs`:
- Around line 28-50: In the boot() function, replace the silent error
conversions (.ok()?) on the spawn() calls for both the iii command and worker
command with proper error handling that logs or panics with the actual error
message rather than converting spawn failures to None, which masks real boot
failures as test skips. Additionally, ensure that if the worker Command spawn
fails after iii has been spawned, the iii child process is properly terminated
before returning to prevent process leaks that affect subsequent tests. The same
fixes should be applied to any other spawn calls in the same function or related
test setup code (around lines 56-59) that have the same silent error conversion
pattern.

In `@context-manager/tests/steps/common_steps.rs`:
- Around line 238-239: The filter_map call on line 238 silently drops any
non-u64 values from parts_value, allowing the assertion to pass with incomplete
sums. Replace the filter_map approach with explicit error handling that panics
if any field under parts cannot be converted to u64. Instead of using filter_map
to skip non-numeric values, iterate through parts_value and explicitly convert
each value to u64, ensuring the code fails fast when encountering non-numeric
fields rather than silently excluding them from the sum calculation.

---

Nitpick comments:
In `@context-manager/Cargo.toml`:
- Around line 37-45: Remove the duplicate dependency declarations from the
dev-dependencies section in Cargo.toml. The dependencies serde_json, uuid, and
tokio are already present in the main dependencies section and do not need to be
redeclared. Delete the lines containing these three packages from the
dev-dependencies block to eliminate maintenance overhead, as Cargo will
automatically make them available for dev targets.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2df0ac11-e9a1-468c-9f5e-e36234ba864b

📥 Commits

Reviewing files that changed from the base of the PR and between 9af1674 and 59fc525.

⛔ Files ignored due to path filters (1)
  • context-manager/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (62)
  • .github/workflows/create-tag.yml
  • .github/workflows/release.yml
  • README.md
  • context-manager/Cargo.toml
  • context-manager/README.md
  • context-manager/build.rs
  • context-manager/config.yaml
  • context-manager/iii.worker.yaml
  • context-manager/src/adapters/mod.rs
  • context-manager/src/adapters/router.rs
  • context-manager/src/adapters/state_lease.rs
  • context-manager/src/config.rs
  • context-manager/src/core/budget.rs
  • context-manager/src/core/estimate.rs
  • context-manager/src/core/lease.rs
  • context-manager/src/core/mod.rs
  • context-manager/src/core/prune.rs
  • context-manager/src/core/selection.rs
  • context-manager/src/core/summary.rs
  • context-manager/src/error.rs
  • context-manager/src/functions/assemble.rs
  • context-manager/src/functions/compact.rs
  • context-manager/src/functions/count_tokens.rs
  • context-manager/src/functions/mod.rs
  • context-manager/src/functions/prune.rs
  • context-manager/src/lib.rs
  • context-manager/src/main.rs
  • context-manager/src/manifest.rs
  • context-manager/src/ports.rs
  • context-manager/src/types.rs
  • context-manager/tests/bdd.rs
  • context-manager/tests/common/engine.rs
  • context-manager/tests/common/fakes.rs
  • context-manager/tests/common/mod.rs
  • context-manager/tests/common/workers.rs
  • context-manager/tests/common/world.rs
  • context-manager/tests/features/assemble.feature
  • context-manager/tests/features/assemble_round_trip.feature
  • context-manager/tests/features/compact.feature
  • context-manager/tests/features/compact_lease.feature
  • context-manager/tests/features/count_tokens.feature
  • context-manager/tests/features/engine_roundtrip.feature
  • context-manager/tests/features/errors.feature
  • context-manager/tests/features/invariants.feature
  • context-manager/tests/features/model_and_budget.feature
  • context-manager/tests/features/prune.feature
  • context-manager/tests/golden/schemas/context.assemble.json
  • context-manager/tests/golden/schemas/context.compact.json
  • context-manager/tests/golden/schemas/context.count_tokens.json
  • context-manager/tests/golden/schemas/context.prune.json
  • context-manager/tests/integration.rs
  • context-manager/tests/manifest.rs
  • context-manager/tests/schemas.rs
  • context-manager/tests/steps/call_steps.rs
  • context-manager/tests/steps/common_steps.rs
  • context-manager/tests/steps/compaction_steps.rs
  • context-manager/tests/steps/engine_steps.rs
  • context-manager/tests/steps/history_steps.rs
  • context-manager/tests/steps/invariant_steps.rs
  • context-manager/tests/steps/mod.rs
  • context-manager/tests/steps/model_steps.rs
  • context-manager/tests/support/mod.rs

Comment on lines +59 to +74
let prior = match store.swap(LEASE_SCOPE, key, claim).await {
Ok(prior) => prior,
Err(e) => {
tracing::warn!(error = %e, key, "lease swap failed; never treating as a win");
return None;
}
};

// We clobbered a still-valid claim (always someone else's — our
// nonce is fresh): restore it and bow out.
if is_active(prior.as_ref(), now, ttl_ms) {
if let Err(e) = store.set(LEASE_SCOPE, key, prior).await {
tracing::warn!(error = %e, key, "lease restore failed");
}
return None;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

Make lease mutation nonce-atomic to preserve mutual exclusion.

Lines 59-74 and Lines 80-84 perform multi-step read/modify/write flows (swapset restore and getset(None) clear). Under contention, a newer holder can be acquired between those calls and then overwritten/cleared by an older path, which allows overlapping compactions.

Use an atomic compare-by-nonce operation in LeaseStore (e.g., CAS / clear_if_nonce) and use that in both acquire restore logic and release.

Also applies to: 80-84

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@context-manager/src/core/lease.rs` around lines 59 - 74, The lease
acquisition and release logic uses non-atomic multi-step operations (swap
followed by set restore, and get followed by set(None) clear) that allow race
conditions where a newer lease holder can be overwritten by an older path. Add
an atomic compare-by-nonce operation to the LeaseStore interface (such as
clear_if_nonce or a similar CAS variant) that atomically checks the nonce before
modifying or clearing the lease. Replace the two-step restore pattern in the
acquire function (the swap followed by the set call when is_active is true) with
a single atomic operation that compares the nonce before restoring. Similarly,
replace the two-step clear pattern in the release function (around lines 80-84)
with the same atomic operation to ensure mutual exclusion is preserved under
contention.

Comment thread context-manager/src/core/prune.rs Outdated
Comment thread context-manager/src/functions/count_tokens.rs
Comment thread context-manager/src/types.rs Outdated
Comment thread context-manager/tests/common/engine.rs
Comment thread context-manager/tests/integration.rs
Comment thread context-manager/tests/steps/common_steps.rs Outdated

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@context-manager/architecture/integration.md`:
- Line 13: The TOC link on line 13 references a fragment anchor for "Structural
invariants" that does not match the actual heading slug generated in the
rendered documentation. Locate the actual "Structural invariants" heading in the
document, determine its correct generated heading slug (typically lowercase with
hyphens replacing spaces and special characters), and update the fragment in the
line 13 link from `#6-structural-invariants-what-you-can-rely-on` to match the
actual heading slug to ensure the navigation link works correctly.

In `@context-manager/src/adapters/fs_lease.rs`:
- Around line 155-199: The async functions `get`, `set`, and `swap` are
performing blocking filesystem I/O operations (ensure_loaded, write_file,
remove_file) while holding a std::sync::Mutex, which blocks Tokio worker
threads. Replace std::sync::Mutex with tokio::sync::Mutex to make the
synchronization async-aware, and refactor the blocking file I/O calls to use
tokio::task::block_in_place within the async context so they run on dedicated
blocking threads instead of starving the async runtime.

In `@harness/src/runtime/compaction.ts`:
- Around line 143-148: The model.limits object is being set with
max_output_tokens defaulted to 0 when the metadata value is not a positive
number, which causes the context-manager to calculate incorrect budgets. Modify
the condition to only assign model.limits when both meta.context_window and
meta.max_output_tokens are positive numbers; if max_output_tokens is missing or
not positive, omit the limits assignment entirely so the router catalog can
provide the correct defaults. Apply this fix wherever model.limits is
conditionally assigned based on metadata values to ensure limits are only
attached when both context and output limits are positive.

In `@harness/src/runtime/session.ts`:
- Around line 258-264: The issue is that the `tail_start_entry_id` assignment
using `tailNew ?? tailLegacy` will resurrect a stale `tail_start_id` value when
`tail_start_entry_id` is explicitly `null` (which means "whole head
summarized"). The nullish coalescing operator treats `null` as a fallback
trigger, but an explicit `null` in the new key should be preserved. Fix this by
checking whether the new key `data.tail_start_entry_id` is actually present in
the data object (using `in` operator or `hasOwnProperty` check) rather than just
whether it's a string, and only fall back to the legacy `tail_start_id` when the
new key is entirely absent, not when it's explicitly `null`.

In `@harness/src/turn-orchestrator/assistant-streaming/run.ts`:
- Around line 49-71: The tools parsed from function_schemas are not being
included in the assembleContext call, which means the pruning/compaction logic
cannot account for their size when calculating the budget. This can cause the
final request to overflow the model limits once tool schemas are attached. Pass
the tools variable (or function_schemas) as a parameter to the
ports.assembleContext function call so the assembly budget includes the tool
schemas when pruning and compacting the window.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a99ea7a-98cc-4945-a0e7-35027a271f47

📥 Commits

Reviewing files that changed from the base of the PR and between 59fc525 and 359b5b9.

⛔ Files ignored due to path filters (1)
  • context-manager/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (95)
  • console/README.md
  • console/web/src/lib/functions.ts
  • context-manager/Cargo.toml
  • context-manager/README.md
  • context-manager/architecture/README.md
  • context-manager/architecture/integration.md
  • context-manager/architecture/internals.md
  • context-manager/config.yaml
  • context-manager/src/adapters/fs_lease.rs
  • context-manager/src/adapters/mod.rs
  • context-manager/src/config.rs
  • context-manager/src/configuration.rs
  • context-manager/src/core/lease.rs
  • context-manager/src/error.rs
  • context-manager/src/functions/assemble.rs
  • context-manager/src/functions/compact.rs
  • context-manager/src/functions/mod.rs
  • context-manager/src/functions/prune.rs
  • context-manager/src/lib.rs
  • context-manager/src/main.rs
  • context-manager/src/manifest.rs
  • context-manager/src/ports.rs
  • context-manager/tests/common/fakes.rs
  • context-manager/tests/common/workers.rs
  • context-manager/tests/common/world.rs
  • harness/docs/workers/context-compaction.md
  • harness/docs/workers/turn-orchestrator.md
  • harness/iii.worker.yaml
  • harness/src/context-compaction/config.ts
  • harness/src/context-compaction/flat-state.ts
  • harness/src/context-compaction/handler-async.ts
  • harness/src/context-compaction/handler-pipeline.ts
  • harness/src/context-compaction/handler-sync.ts
  • harness/src/context-compaction/iii.worker.yaml
  • harness/src/context-compaction/lease.ts
  • harness/src/context-compaction/main.ts
  • harness/src/context-compaction/model-resolver.ts
  • harness/src/context-compaction/overflow.ts
  • harness/src/context-compaction/prompts/compaction.txt
  • harness/src/context-compaction/prune.ts
  • harness/src/context-compaction/register.ts
  • harness/src/context-compaction/replay.ts
  • harness/src/context-compaction/selection.ts
  • harness/src/context-compaction/strip-media.ts
  • harness/src/context-compaction/summarize.ts
  • harness/src/context-compaction/template.ts
  • harness/src/index.ts
  • harness/src/runtime/compaction.ts
  • harness/src/runtime/lease.ts
  • harness/src/runtime/session.ts
  • harness/src/turn-orchestrator/assistant-streaming/ports.ts
  • harness/src/turn-orchestrator/assistant-streaming/run.ts
  • harness/src/turn-orchestrator/errors.ts
  • harness/src/turn-orchestrator/events.ts
  • harness/src/turn-orchestrator/preflight.ts
  • harness/src/turn-orchestrator/state-runtime/context-view.ts
  • harness/src/turn-orchestrator/state-runtime/ports.ts
  • harness/src/turn-orchestrator/state-runtime/store.ts
  • harness/src/turn-orchestrator/state-runtime/turn-end.ts
  • harness/src/turn-orchestrator/state.ts
  • harness/src/types/agent-event.ts
  • harness/tests/_helpers/fakeSessionManager.ts
  • harness/tests/context-compaction/compact-session-registered.test.ts
  • harness/tests/context-compaction/compact-session.test.ts
  • harness/tests/context-compaction/compaction-done-emit.test.ts
  • harness/tests/context-compaction/e2e/full-session.test.ts
  • harness/tests/context-compaction/handler-async.test.ts
  • harness/tests/context-compaction/handler-sync.test.ts
  • harness/tests/context-compaction/integration/backward-compat.test.ts
  • harness/tests/context-compaction/integration/flow-async.test.ts
  • harness/tests/context-compaction/integration/flow-prune.test.ts
  • harness/tests/context-compaction/integration/flow-sync.test.ts
  • harness/tests/context-compaction/lease.test.ts
  • harness/tests/context-compaction/overflow.test.ts
  • harness/tests/context-compaction/prune.test.ts
  • harness/tests/context-compaction/registration.test.ts
  • harness/tests/context-compaction/replay.test.ts
  • harness/tests/context-compaction/selection.test.ts
  • harness/tests/context-compaction/strip-media.test.ts
  • harness/tests/context-compaction/summarize.test.ts
  • harness/tests/context-compaction/template.test.ts
  • harness/tests/runtime/compaction.test.ts
  • harness/tests/turn-orchestrator/_helpers/mockTurnStore.ts
  • harness/tests/turn-orchestrator/assistant-streaming.test.ts
  • harness/tests/turn-orchestrator/assistant.test.ts
  • harness/tests/turn-orchestrator/context-view.test.ts
  • harness/tests/turn-orchestrator/events.test.ts
  • harness/tests/turn-orchestrator/finish.test.ts
  • harness/tests/turn-orchestrator/function-awaiting-approval.test.ts
  • harness/tests/turn-orchestrator/function-execute.test.ts
  • harness/tests/turn-orchestrator/functions.test.ts
  • harness/tests/turn-orchestrator/preflight.test.ts
  • harness/tests/turn-orchestrator/run-transition.test.ts
  • harness/tests/turn-orchestrator/store.test.ts
  • iii-permissions.yaml
💤 Files with no reviewable changes (44)
  • harness/tests/context-compaction/replay.test.ts
  • console/web/src/lib/functions.ts
  • harness/tests/context-compaction/prune.test.ts
  • harness/src/context-compaction/template.ts
  • harness/tests/context-compaction/handler-async.test.ts
  • harness/src/context-compaction/flat-state.ts
  • harness/src/context-compaction/model-resolver.ts
  • harness/tests/context-compaction/integration/backward-compat.test.ts
  • harness/tests/context-compaction/lease.test.ts
  • harness/tests/context-compaction/handler-sync.test.ts
  • harness/tests/context-compaction/overflow.test.ts
  • harness/src/context-compaction/config.ts
  • harness/src/context-compaction/handler-sync.ts
  • harness/src/context-compaction/replay.ts
  • harness/tests/turn-orchestrator/functions.test.ts
  • harness/tests/context-compaction/e2e/full-session.test.ts
  • harness/src/context-compaction/prompts/compaction.txt
  • harness/tests/context-compaction/compact-session.test.ts
  • harness/tests/turn-orchestrator/_helpers/mockTurnStore.ts
  • harness/tests/turn-orchestrator/store.test.ts
  • harness/src/context-compaction/strip-media.ts
  • harness/tests/context-compaction/strip-media.test.ts
  • harness/tests/context-compaction/integration/flow-prune.test.ts
  • harness/src/context-compaction/lease.ts
  • harness/src/types/agent-event.ts
  • harness/src/context-compaction/selection.ts
  • harness/tests/context-compaction/integration/flow-sync.test.ts
  • harness/src/context-compaction/overflow.ts
  • harness/src/context-compaction/handler-async.ts
  • harness/tests/turn-orchestrator/function-awaiting-approval.test.ts
  • harness/tests/turn-orchestrator/context-view.test.ts
  • harness/tests/context-compaction/selection.test.ts
  • harness/tests/context-compaction/integration/flow-async.test.ts
  • harness/tests/context-compaction/template.test.ts
  • harness/tests/turn-orchestrator/preflight.test.ts
  • harness/tests/context-compaction/summarize.test.ts
  • harness/tests/context-compaction/compaction-done-emit.test.ts
  • harness/src/turn-orchestrator/preflight.ts
  • harness/src/turn-orchestrator/state-runtime/context-view.ts
  • harness/src/turn-orchestrator/state-runtime/store.ts
  • harness/src/context-compaction/handler-pipeline.ts
  • harness/src/context-compaction/prune.ts
  • harness/src/context-compaction/summarize.ts
  • harness/tests/turn-orchestrator/assistant.test.ts
✅ Files skipped from review due to trivial changes (7)
  • console/README.md
  • harness/src/runtime/lease.ts
  • harness/src/context-compaction/main.ts
  • harness/src/turn-orchestrator/state.ts
  • harness/src/index.ts
  • harness/docs/workers/turn-orchestrator.md
  • context-manager/README.md
🚧 Files skipped from review as they are similar to previous changes (15)
  • context-manager/src/adapters/mod.rs
  • context-manager/config.yaml
  • context-manager/src/lib.rs
  • context-manager/Cargo.toml
  • context-manager/src/error.rs
  • context-manager/src/functions/prune.rs
  • context-manager/tests/common/workers.rs
  • context-manager/src/functions/assemble.rs
  • context-manager/src/manifest.rs
  • context-manager/src/core/lease.rs
  • context-manager/src/functions/mod.rs
  • context-manager/src/ports.rs
  • context-manager/src/functions/compact.rs
  • context-manager/tests/common/world.rs
  • context-manager/tests/common/fakes.rs

Comment thread context-manager/architecture/integration.md
Comment thread context-manager/src/adapters/fs_lease.rs
Comment thread harness/src/runtime/compaction.ts
Comment thread harness/src/runtime/session.ts
Comment thread harness/src/turn-orchestrator/assistant-streaming/run.ts

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (2)
context-manager/architecture/integration.md (1)

13-13: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

** Fix the broken TOC anchor for Structural invariants** — this was already flagged in a previous review and still needs correction.

Line 13's link fragment doesn't match the heading slug generated from the actual "Structural invariants" heading at line 269. The em-dash in the heading (## 6. Structural invariants — what you can rely on) will render as a different slug in the anchor.

🔗 Proposed fix
-[structural invariants](`#6-structural-invariants-what-you-can-rely-on`) ·
+[structural invariants](`#6-structural-invariants--what-you-can-rely-on`) ·

(Note: Markdown renderers typically convert the em-dash to -- in the slug; verify the exact slug in your target renderer and adjust if needed.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@context-manager/architecture/integration.md` at line 13, The table of
contents anchor link on line 13 contains an incorrect fragment reference for the
"Structural invariants" heading. Update the anchor fragment in the TOC link from
the current value to match the actual slug generated by the heading at line 269.
Since the heading contains an em-dash (—) which markdown renderers typically
convert to double hyphens (--) in the slug, change the anchor fragment to use
the correct slug pattern that corresponds to how the "6. Structural invariants —
what you can rely on" heading will be rendered, verifying the exact slug syntax
your markdown renderer produces.
context-manager/src/functions/count_tokens.rs (1)

20-65: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

messages is schema-optional but runtime-required — this breaks the API contract.

Line 20 declares messages optional, but Line 63-Line 65 rejects missing values as invalid. This allows clients to send schema-valid requests that fail at runtime. Make messages required in CountTokensRequest and remove the runtime ok_or_else guard, then regenerate the golden schema so "messages" is required too.

Proposed fix
 pub struct CountTokensRequest {
     /// Messages to estimate, oldest first.
-    pub messages: Option<Vec<AgentMessage>>,
+    pub messages: Vec<AgentMessage>,
@@
 ) -> Result<CountTokensResponse, ContextError> {
-    let messages = req
-        .messages
-        .ok_or_else(|| ContextError::InvalidRequest("messages is required".into()))?;
+    let messages = req.messages;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@context-manager/src/functions/count_tokens.rs` around lines 20 - 65, The
messages field in CountTokensRequest is declared as Option<Vec<AgentMessage>>
making it schema-optional, but the handle function requires it at runtime using
ok_or_else, creating an API contract mismatch. Remove the Option wrapper from
the messages field in CountTokensRequest so it becomes Vec<AgentMessage>
(required), then remove the ok_or_else guard in the handle function since
messages will always be present, and finally regenerate the golden schema to
reflect that messages is a required field.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@context-manager/architecture/integration.md`:
- Line 13: The table of contents anchor link on line 13 contains an incorrect
fragment reference for the "Structural invariants" heading. Update the anchor
fragment in the TOC link from the current value to match the actual slug
generated by the heading at line 269. Since the heading contains an em-dash (—)
which markdown renderers typically convert to double hyphens (--) in the slug,
change the anchor fragment to use the correct slug pattern that corresponds to
how the "6. Structural invariants — what you can rely on" heading will be
rendered, verifying the exact slug syntax your markdown renderer produces.

In `@context-manager/src/functions/count_tokens.rs`:
- Around line 20-65: The messages field in CountTokensRequest is declared as
Option<Vec<AgentMessage>> making it schema-optional, but the handle function
requires it at runtime using ok_or_else, creating an API contract mismatch.
Remove the Option wrapper from the messages field in CountTokensRequest so it
becomes Vec<AgentMessage> (required), then remove the ok_or_else guard in the
handle function since messages will always be present, and finally regenerate
the golden schema to reflect that messages is a required field.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ce45f8b-d3ef-4a16-a1c0-a1eda8e7176b

📥 Commits

Reviewing files that changed from the base of the PR and between 31e9d21 and 38fe720.

📒 Files selected for processing (21)
  • context-manager/README.md
  • context-manager/architecture/README.md
  • context-manager/architecture/integration.md
  • context-manager/architecture/internals.md
  • context-manager/src/core/estimate.rs
  • context-manager/src/functions/count_tokens.rs
  • context-manager/src/functions/mod.rs
  • context-manager/src/types.rs
  • context-manager/tests/common/workers.rs
  • context-manager/tests/common/world.rs
  • context-manager/tests/features/count_tokens.feature
  • context-manager/tests/features/engine_roundtrip.feature
  • context-manager/tests/features/errors.feature
  • context-manager/tests/golden/schemas/context.count-tokens.json
  • context-manager/tests/integration.rs
  • context-manager/tests/schemas.rs
  • context-manager/tests/steps/call_steps.rs
  • docs/sops/binary-worker.md
  • docs/sops/new-worker.md
  • tech-specs/2026-06-agentic/context-manager.md
  • tech-specs/2026-06-agentic/presentation/src/content/workers.ts
✅ Files skipped from review due to trivial changes (5)
  • docs/sops/new-worker.md
  • docs/sops/binary-worker.md
  • context-manager/architecture/README.md
  • context-manager/README.md
  • context-manager/architecture/internals.md
🚧 Files skipped from review as they are similar to previous changes (9)
  • context-manager/tests/schemas.rs
  • context-manager/tests/features/errors.feature
  • context-manager/src/core/estimate.rs
  • context-manager/tests/steps/call_steps.rs
  • context-manager/tests/features/engine_roundtrip.feature
  • context-manager/tests/common/workers.rs
  • context-manager/src/functions/mod.rs
  • context-manager/tests/common/world.rs
  • context-manager/src/types.rs

@sergiofilhowz sergiofilhowz merged commit e961088 into main Jun 15, 2026
22 checks passed
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.

2 participants