Skip to content

Apply the Closura thread type policy at turn start (CLO-924) - #114

Merged
nullStack65 merged 3 commits into
release/native-0.1.10from
feat/clo-924-thread-type-policy
Nov 20, 2026
Merged

nullStack65 merged 3 commits into
release/native-0.1.10from
feat/clo-924-thread-type-policy

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Problem

Kameron approved per-thread-type cache and compaction settings and taking gpt-6-astra off standing role threads (CLO-924, from the token burn report in closura-agent-config PR 953). closura-agent-config PR 957 adds the one policy table and installs it on every synced host at ~/.config/closura/thread-type-policy.json. This PR makes the fork honor it.

Behavior

  1. ThreadTypePolicy.ts reads and validates the table and classifies a thread: the T3 standing persona wins, then a [type] title tag, then the title rules (child threads skip the top-level-only rules), then the default. T3_THREAD_TYPE_POLICY_PATH overrides the path.
  2. RuntimePolicyV2.resolve applies it at every turn start, after the runtime mode ceiling. A refused model fails with ThreadTypeModelRefusedError, which ProviderTurnStartService settles as "Model refused on this thread type" with the policy message. The resolved policy carries threadType (type, context window, compaction point, cache TTL).
  3. Claude: autoCompactWindow becomes the policy window. CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is compact_at divided by the effective window (the model context, capped at the 272k policy window, minus Claude's 20k output reserve), rounded up to two decimals. CLAUDE_CODE_PROMPT_CACHE_TTL is set to the type's TTL so it wins over the setting and over a subagent or instance TTL. The reported threshold uses that same formula. If auto-compact is disabled, no threshold is reported.
  4. Codex: thread config gets model_auto_compact_token_limit only. It does not set model_context_window.
  5. A missing file keeps today's behavior and warns once. An unreadable or invalid file, including a title pattern JavaScript cannot compile, logs one warning and does the same.
  6. The standing refusal matches the last path segment, then strips an openai. slug, [1m], and a trailing -fast. Dispatch and checkpoint rollback show that refusal message.

Prior art

  1. The existing managed-policy ceiling in RuntimePolicy.ts (refuseAboveCeiling): the refusal follows the same pattern and settle path.
  2. The first-class standing thread property (PR 110) is the standing signal; titles are only the fallback.
  3. Stock harness knobs only: Claude Code promptCacheTtl, autoCompactWindow, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, CLAUDE_CODE_PROMPT_CACHE_TTL; Codex model_auto_compact_token_limit.

Evidence

  1. pnpm run typecheck in apps/server: clean.
  2. vp test run on ThreadTypePolicy, RuntimePolicy, ClaudeAdapterV2, CodexAdapterV2, GrokAdapterV2 and ProviderTurnStartService: 769 pass. Two fail locally (Claude native fork, Grok multi-select question) and fail the same way on the untouched base, because this host's Node 22 cannot strip TypeScript in a spawned child.
  3. New tests: classification cases, astra refused on standing including stacked prefixes, openai. slugs, -fast, and [1m], per-type values, a JavaScript-invalid pattern failing open, RuntimePolicy refusal and threadType from a fixture file, Claude percent and cache env, Codex compaction limit without a context-window override, and the dispatch error showing the refusal message.
  4. Review repair is commit a889e48. Local vp test run on ThreadTypePolicy, the thread-type cases in ClaudeAdapterV2 and CodexAdapterV2, RuntimePolicy, and UserFacingErrors passed. Full typecheck was not rerun on this host because the load was already high.

Deploy: fleet

Model: claude-opus-5-5
Task: CLO-924
Agent: claude-code
Lane: magpie
Harness: t3/claude-code
Model-family: Claude
Model-generation: 5.5
Skills-SHA: 709beb59
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

🤖 Generated with Claude Code

nullStack65 and others added 3 commits November 20, 2026 01:21
RuntimePolicy reads ~/.config/closura/thread-type-policy.json (installed by
closura-agent-config machine_sync) and classifies each thread as standing,
coding, review, research, ops or conversational. A model the type refuses,
such as gpt-6-astra on a standing thread, fails the turn start with a clear
message. Claude turns get the type's prompt cache TTL and compaction point;
Codex threads get model_context_window and model_auto_compact_token_limit.
A missing or invalid policy file keeps today's behavior.

Model: claude-opus-5-5
Task: CLO-924
Agent: claude-code
Lane: magpie
Harness: t3/claude-code
Model-family: Claude
Model-generation: 5.5
Skills-SHA: 709beb59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude's percent override now targets the effective window, the model's context minus the 20k output reserve, so the compaction point matches the table. The cache TTL is set on the env var Claude ranks above the setting. A disabled auto-compact still reports no threshold. Codex receives only the compaction limit. Refusal covers stacked prefixes, openai. slugs, a trailing -fast, and [1m]. A title pattern JavaScript cannot compile fails open with one warning, and a missing policy warns once. Dispatch and rollback surface the refusal message.

Model: grok/grok-4.7
Task: CLO-924
Agent: grok
Lane: magpie
Harness: t3/codex
Model-family: Grok
Model-generation: 4.7
Skills-SHA: e6cf8938; skills/github-repository-ops/SKILL.md, docs/delivery/provenance-trailers.md
Co-Authored-By: Grok 4.7 <noreply@x.ai>
The refusal test read model off the whole resolve error union, so the server
typecheck exited 2 and the Linux ARC check failed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@nullStack65

Copy link
Copy Markdown
Owner Author
{"reviewed_head":"9a2413c66e1ce9e8b23085ca42fc1cf6e094c3c1","reviewer":"grok-4.7-build (claudeAgent, read-only)","findings":[]}

@nullStack65
nullStack65 merged commit f7626c1 into release/native-0.1.10 Nov 20, 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.

1 participant