D1: Persist turn context diagnostics with scoped occupancy queries #798

Merged
toasterson merged 5 commits from feat/d1-context-diagnostics-20261019 into main 2026-10-19 20:02:18 +00:00
Owner

D1 persists content-free typed model_observation, turn_usage and context_transform receipts alongside the central projection cursor. Exact immutable replay is a no-op; changed content/lineage records an invalid observation with unknown usage and projection continues. It preserves actual token/cache counts, unknown/zero distinctions, actual context occupancy/window/source, finish/terminal reasons, continuation/final-message byte census and compaction/elision provenance. SDK snapshots remain non-additive; this diagnostic path does not mutate canonical session cost totals.

WI detail and the scoped get_context_diagnostics MCP read expose bounded observations, an exact session filter, stable cursor and turn filters over_80_percent / length_or_incomplete. Session-WI identity and PAT project WorkItemRead permission are enforced. Query failures are errors/unavailable. Dispatch staging records the final rendered prompt hash and exact UTF-8 section bytes when component spans are unambiguous. Section token counts and runtime tool/history section breakdown remain explicitly unknown where no tokenizer/census exists. Dispatch-only sections are never presented as resumed model input.

Migration157 adds immutable receipts, dispatch census and central_turn_context_diagnostics query view. Wire DTOs are additive consumers of Akh telemetry #677 and D1 #678. Runtime dependency: compatible readers upgraded first, live jobs drained, AKH_RUNTIME_MODEL_EVENT_CONSUMER=model-events-v1 and AKH_RUNTIME_LEGACY_EVENTS=false; old runtimes/legacy projection yield no rows and historical absence stays unknown. Related Q2 #796 final-budget and Q3 #797 cost-view fixes remain separate concerns. Full contract: docs/ai/contracts/context-diagnostics-v1.md.

Validation: 558 server lib tests passed/6 environment-dependent ignored; full-schema PostgreSQL replay/unknown/zero/filter/cursor/ACL fixture passed. Existing production central projection fixture passes with new telemetry, changed immutable content retained as invalid while rows/cursor/replies continue, and exact duplicate summary accounting once. Final immutable prompt-census regression passed. Nightly CI runs the focused diagnostic database fixture. Scoped formatting, diff/shell checks and CI dry-run pass.

Solstice exact-head CI and independent review remain pending under the shared dispatch incident owned by round16. Local tests are not CI or runtime acceptance. Do not merge: operator human gate. No deployment, polling, compaction-policy change or live recovery action.

Fable follow-up: invalid/unsupported telemetry and changed immutable IDs now produce bounded invalid_observation receipts with unknown usage, static cause and SHA256; raw invalid payload is not persisted. Original immutable rows are preserved. Projection uses a savepoint so diagnostic failures cannot block the durable cursor, later replies or completion. Legacy post-claim census is best-effort and non-fatal. Regression coverage includes malformed usage, future source, malformed usage and unsupported sources, changed IDs, missing census storage and continued terminal replies.

ACL disclosure: get_work_item_detail now requires an exact-WI session anchor or PAT project WorkItemRead. This affects the whole detail response, including legacy fields; plan/companion session tokens without a WI anchor are denied. The dedicated diagnostic tool has the same boundary. Q4 separately preserves plan/companion project binding for its seven artifact tools.

Final Akh#678 d322e08bbcc8112bbe4291089a620dd5996833aa is consumed additively: event.usage.failure_cause and event.observation.failure_cause, normalized terminal_code (incomplete -> model_incomplete), nullable usage_known_calls, Codex provider-reported modelContextWindow/occupancy. Unknown historical fields remain null. Compatible readers must be upgraded first, jobs drained, then the runtime model-events-v1 consumer acknowledgment and modern events enabled. This PR performs no deployment.

Follow-up validation:559server unit tests passed/6ignored; full-schema diagnostics/query/census regression passed; production journal projection regression passed changed immutable IDs, unsupported source, valid Qwen display label, malformed usage and a subsequent final thread reply. Exact replay leaves one receipt; cursor reaches17. No modern transport activation performed.

Round2 follow-up: display labels reported_model/requested_model/provider/finish_reason/runtime accept bounded printable UTF8 (<=256bytes, no controls), separately from strict IDs/hashes. Exact Qwen3 235B (Q4_K_M) label now persists with actual usage. After rollout, watch session-token MCP denials containing permission_denied: exact work item required on get_work_item_detail, especially plan/companion callers without a WI anchor. No rollout is performed here. Modern runtime drain enforcement additionally requires AKH_DEPLOYMENT=deployed, compatible readers first, jobs drained, model-events-v1 acknowledgment and legacy events disabled.

Integration refresh (2026-10-19): normal main/dependency merge commits, no force push. Main is 8d3eb5855f. This head also includes refreshed #796 so the agreed merge order cannot repeat the same insertion conflict; its diff narrows as predecessors land. Shell/Rust syntax, diff and predecessor-ancestry checks pass. No fresh local cargo check: available disk headroom above the 31.25 GiB floor was smaller than the last measured owned compile target. Exact new-head CI is the gate; prior receipts remain prior-head evidence.

D1 persists content-free typed model_observation, turn_usage and context_transform receipts alongside the central projection cursor. Exact immutable replay is a no-op; changed content/lineage records an invalid observation with unknown usage and projection continues. It preserves actual token/cache counts, unknown/zero distinctions, actual context occupancy/window/source, finish/terminal reasons, continuation/final-message byte census and compaction/elision provenance. SDK snapshots remain non-additive; this diagnostic path does not mutate canonical session cost totals. WI detail and the scoped get_context_diagnostics MCP read expose bounded observations, an exact session filter, stable cursor and turn filters over_80_percent / length_or_incomplete. Session-WI identity and PAT project WorkItemRead permission are enforced. Query failures are errors/unavailable. Dispatch staging records the final rendered prompt hash and exact UTF-8 section bytes when component spans are unambiguous. Section token counts and runtime tool/history section breakdown remain explicitly unknown where no tokenizer/census exists. Dispatch-only sections are never presented as resumed model input. Migration157 adds immutable receipts, dispatch census and central_turn_context_diagnostics query view. Wire DTOs are additive consumers of Akh telemetry #677 and D1 #678. Runtime dependency: compatible readers upgraded first, live jobs drained, AKH_RUNTIME_MODEL_EVENT_CONSUMER=model-events-v1 and AKH_RUNTIME_LEGACY_EVENTS=false; old runtimes/legacy projection yield no rows and historical absence stays unknown. Related Q2 #796 final-budget and Q3 #797 cost-view fixes remain separate concerns. Full contract: docs/ai/contracts/context-diagnostics-v1.md. Validation: 558 server lib tests passed/6 environment-dependent ignored; full-schema PostgreSQL replay/unknown/zero/filter/cursor/ACL fixture passed. Existing production central projection fixture passes with new telemetry, changed immutable content retained as invalid while rows/cursor/replies continue, and exact duplicate summary accounting once. Final immutable prompt-census regression passed. Nightly CI runs the focused diagnostic database fixture. Scoped formatting, diff/shell checks and CI dry-run pass. Solstice exact-head CI and independent review remain pending under the shared dispatch incident owned by round16. Local tests are not CI or runtime acceptance. **Do not merge: operator human gate.** No deployment, polling, compaction-policy change or live recovery action. Fable follow-up: invalid/unsupported telemetry and changed immutable IDs now produce bounded invalid_observation receipts with unknown usage, static cause and SHA256; raw invalid payload is not persisted. Original immutable rows are preserved. Projection uses a savepoint so diagnostic failures cannot block the durable cursor, later replies or completion. Legacy post-claim census is best-effort and non-fatal. Regression coverage includes malformed usage, future source, malformed usage and unsupported sources, changed IDs, missing census storage and continued terminal replies. ACL disclosure: get_work_item_detail now requires an exact-WI session anchor or PAT project WorkItemRead. This affects the whole detail response, including legacy fields; plan/companion session tokens without a WI anchor are denied. The dedicated diagnostic tool has the same boundary. Q4 separately preserves plan/companion project binding for its seven artifact tools. Final Akh#678 d322e08bbcc8112bbe4291089a620dd5996833aa is consumed additively: event.usage.failure_cause and event.observation.failure_cause, normalized terminal_code (incomplete -> model_incomplete), nullable usage_known_calls, Codex provider-reported modelContextWindow/occupancy. Unknown historical fields remain null. Compatible readers must be upgraded first, jobs drained, then the runtime model-events-v1 consumer acknowledgment and modern events enabled. This PR performs no deployment. Follow-up validation:559server unit tests passed/6ignored; full-schema diagnostics/query/census regression passed; production journal projection regression passed changed immutable IDs, unsupported source, valid Qwen display label, malformed usage and a subsequent final thread reply. Exact replay leaves one receipt; cursor reaches17. No modern transport activation performed. Round2 follow-up: display labels reported_model/requested_model/provider/finish_reason/runtime accept bounded printable UTF8 (<=256bytes, no controls), separately from strict IDs/hashes. Exact Qwen3 235B (Q4_K_M) label now persists with actual usage. After rollout, watch session-token MCP denials containing permission_denied: exact work item required on get_work_item_detail, especially plan/companion callers without a WI anchor. No rollout is performed here. Modern runtime drain enforcement additionally requires AKH_DEPLOYMENT=deployed, compatible readers first, jobs drained, model-events-v1 acknowledgment and legacy events disabled. <!-- anima-main-refresh-20261019:begin --> Integration refresh (2026-10-19): normal main/dependency merge commits, no force push. Main is 8d3eb5855f74c616d176b788e2ca881d2f933e3f. This head also includes refreshed #796 so the agreed merge order cannot repeat the same insertion conflict; its diff narrows as predecessors land. Shell/Rust syntax, diff and predecessor-ancestry checks pass. No fresh local cargo check: available disk headroom above the 31.25 GiB floor was smaller than the last measured owned compile target. Exact new-head CI is the gate; prior receipts remain prior-head evidence. <!-- anima-main-refresh-20261019:end -->
Persist typed turn context diagnostics and expose bounded scoped reads
All checks were successful
CI / conflict-check (push) Successful in 46s
CI / test (push) Successful in 8m33s
72c8d0ef49
fix: isolate invalid telemetry from journal and legacy dispatch progress
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
bd369174b4
fix: accept bounded provider display labels without weakening identifiers
All checks were successful
CI / conflict-check (push) Successful in 5m37s
CI / test (push) Successful in 20m37s
17030d469b
Merge current main into D1, preserving context and conflict detail fields
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
3e48011285
Persist central provider cooldowns and gate fresh admission
Some checks failed
CI / conflict-check (push) Successful in 50s
CI / test (push) Has been cancelled
eeaa095cf3
Refuse oversized final dispatch briefs without losing mandatory input
All checks were successful
CI / conflict-check (push) Successful in 1m5s
CI / test (push) Successful in 9m13s
fd0c99bb8f
Queue usage-limited providers behind durable reset windows and one probe
Some checks failed
CI / conflict-check (push) Successful in 37s
CI / test (push) Has been cancelled
256b2df4a5
Label transcript sources and enforce explicit byte-tail and native cursor semantics
Some checks failed
CI / conflict-check (push) Successful in 8m35s
CI / test (push) Failing after 8m4s
85e43729fe
fix: recover ended limit probes and audit bounded operator clearing
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
465f8fe9f8
Merge Q1 dependency to validate provider and allocation lock scope
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
03ad2d0929
# Conflicts:
#	.solstice/job.sh
test: cover all seven artifact tools sharing exact work-item ACL
Some checks failed
CI / test (push) Failing after 6m35s
CI / conflict-check (push) Successful in 8m11s
98f1cac6ff
fix: settle cancelled provider probes through completion observation
All checks were successful
CI / conflict-check (push) Successful in 2m7s
CI / test (push) Successful in 7m23s
68a739f929
Merge Q1 cancelled-probe followup into brief-budget dependency
All checks were successful
CI / conflict-check (push) Successful in 3m0s
CI / test (push) Successful in 9m42s
ae9218991c
Fix transcript boundary Clippy findings from exact-head CI
All checks were successful
CI / conflict-check (push) Successful in 37s
CI / test (push) Successful in 6m24s
76cbc9c555
Merge current main into Q4, preserving transcript and conflict CI jobs
All checks were successful
CI / conflict-check (push) Successful in 41s
CI / test (push) Successful in 15m51s
bce6f02766
Merge current main into Q1, retaining usage and conflict diagnostics
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
42a8e9498b
Merge current main into Q2 with validated diagnostic and CI resolutions
Some checks failed
CI / conflict-check (push) Has been cancelled
CI / test (push) Has been cancelled
c424888e2b
Integrate refreshed Q4 dependency so Q1 merges cleanly in order
All checks were successful
CI / test (push) Successful in 7m33s
CI / conflict-check (push) Successful in 33m34s
7bd713fa2b
Integrate refreshed Q1 and Q4 dependencies before Q2
All checks were successful
CI / test (push) Successful in 7m48s
CI / conflict-check (push) Successful in 21m21s
ebf87a5ceb
Integrate refreshed Q2 dependencies into D1 with validated prompt assembly
All checks were successful
CI / conflict-check (push) Successful in 43s
CI / test (push) Successful in 8m5s
36d3cb084f
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
toasterson/Anima!798
No description provided.