Skip to content

fix: derive context_compaction capability from controls, remove has_hook config - #139

Merged
tishachawla-jg merged 2 commits into
theagentplane:mainfrom
RjyavardhanSingh:fix/138-context-compaction-defaults
Sep 17, 2026
Merged

tishachawla-jg merged 2 commits into
theagentplane:mainfrom
RjyavardhanSingh:fix/138-context-compaction-defaults

Conversation

@RjyavardhanSingh

Copy link
Copy Markdown
Contributor

Problem

Fixes #138

context_compaction was the only policy with a has_hook flag — a host capability masquerading as governance config. Three defaults disagreed (code: True, yaml: false, Admin UI: false), and the shipped default was wrong for the documented integration path: wrap_complete already supplies the prompt-assembly hook, so every Tier-1 quickstart user has the hook but the config said they didn't.

The policy appeared enabled in the dashboard while silently doing nothing.

What changed

  • Removed has_hook from ContextCompactionPolicy, build(), config template, default.yaml, Admin UI placeholder, and all example/benchmark configs
  • Added compaction_supported to ApplyControls — set by wrap_complete which IS the hook
  • Derived capability at runtime via a context variable (_current_controls) set in Governor._enforce(), so the policy reads controls instead of a config flag
  • Logged a one-time warning when compaction degrades to telemetry (no hook available)
  • Updated tests to exercise both paths (compaction supported / not supported)

Why this approach

Option 1 from the issue: "derive it." Capability belongs with actuator plumbing, not a governance record. wrap_complete advertises the capability because it IS the hook — correct by construction, no config needed.

A context variable avoids changing the Policy.decide() ABC (which would require updating all 10 policies).

Files changed

File Change
src/tokenops/control/policies/context_compaction.py Remove has_hook, derive from controls, add warning
src/tokenops/control/engine.py Add compaction_supported to ApplyControls, set context var in _enforce()
src/tokenops/control/context.py Add _current_controls ContextVar + helpers
src/tokenops/control/integration.py Set controls.compaction_supported = True in wrap_complete
src/tokenops/control/config.py Remove has_hook from template
src/tokenops/config/default.yaml Remove has_hook
src/tokenops/ui/views/admin.py Remove has_hook from placeholder
tests/test_context_compaction.py Update tests for new API
tests/test_actuators.py Remove has_hook from build call
tests/test_policies_wrap_integration.py Remove has_hook from build call
benchmarking/*/configs.py (3 files) Remove has_hook from configs
examples/config/*.yaml (5 files) Remove has_hook from configs
docs/policies/context_compaction.md Document where hook comes from
CHANGELOG.md Document behaviour change

Acceptance criteria

  • Three defaults agree (removed has_hook entirely)
  • Tier-1 quickstart gets working compaction without editing policy source
  • Inert policy is discoverable without reading a reason string (warning logged)
  • Host capability is not in governance record
  • docs/policies/context_compaction.md states where hook comes from

Behaviour change

Anyone relying on context_compaction being silently inert will now get working compaction (prompts rewritten). This is the fix, not a regression — documented in changelog.

Non-scope

@tishachawla-jg

Copy link
Copy Markdown
Collaborator

Hi @RjyavardhanSingh, can you please resolve the conflicts also examples/config/default.yaml also swaps model: gpt-4o-mini → gemini-2.0-flash in 5 places while keeping provider: openai. That's unrelated to this fix and an inconsistent config (OpenAI provider + Gemini model won't resolve), looks like a local-testing artifact. Could you revert those 5 lines?

@RjyavardhanSingh

Copy link
Copy Markdown
Contributor Author

@tishachawla-jg Got it, will fix both unning ruff format on context_compaction.py and reverting the gemini model changes in examples/config/default.yaml. Should be ready shortly. i had changed that for local testing but forgot to restore my bad sorry for that

…ook config

context_compaction took a has_hook flag that no other policy has. It
described host capability (whether the prompt-assembly hook exists) as
a governance config field — mixing intent with capability. The three
defaults disagreed (code: True, yaml: false, admin: false), and the
shipped default was wrong for the documented integration path
(wrap_complete already supplies the hook).

- Remove has_hook from ContextCompactionPolicy, build(), config
  template, default.yaml, admin UI, and all example configs
- Add compaction_supported flag to ApplyControls, set by wrap_complete
- Policy reads capability via context variable set in Governor._enforce()
- Log a one-time warning when compaction degrades to telemetry
- Update tests, docs, and changelog

Closes theagentplane#138
@RjyavardhanSingh
RjyavardhanSingh force-pushed the fix/138-context-compaction-defaults branch from 7dc962a to e6986d4 Compare September 16, 2026 18:58
@tishachawla-jg
tishachawla-jg merged commit 340aad1 into theagentplane:main Sep 17, 2026
3 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.

Design smell: context_compaction's has_hook is host capability in a governance record, and ships inert by default

2 participants