feat(daemon): compact Codex context at inherited token limit#926
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a parent-controlled context-token threshold for
backend="lingtai"daemon tasks and compact Codex Responses provider context when the threshold is reached, without folding the current live turn into the opaque compacted prefix.TaskConfig.context_token_limitis optional; when omitted, daemon dispatch inherits the parent agent's resolved context-token value.message+compaction_summaryitems unchanged.User contract and live endpoint evidence
Before implementation, a minimal live probe called
POST /backend-api/codex/responses/compactwithgpt-5.6-sol. It returned canonical opaque compaction items; replaying those items unchanged plus a new user item returned the exact continuation marker. The probe did not mutate authentication and did not persist tokens, account data, or opaque response content.Implementation
context_token_limitto LingTai daemon task schema/runtime state and inherit the parent resolved context window when omitted.Review and repair history
Exact Opus 4.8 review v1 returned NOT READY with 0 blocker, 2 high, 2 medium:
DAEMON_CONTRACT.mdlockstep was incomplete.The repair keeps the live turn outside the compacted prefix, switches to projected pre-send triggering, uses real
send()plain/tool-result tests, and updates contract lockstep.Sol then found two additional acceptance gaps and repaired them before this update:
[opaque compacted prefix + live suffix], while local calibration measured full raw history; calibration now uses the exact rendered request sent;compact_calls == 2, while the final rendered request was still11359 > LIMIT 11340; the standalone boundary now retains one complete live turn and the regression asserts the actual rendered-request upper bound.Validation
Validation used the actual LingTai runtime Python 3.13.14 with bytecode disabled and no local pytest cleanup lifecycle.
adapter.py, daemon__init__.py, and the focused compaction test — pass.11340;11264 < 11340;1;2;84 < 11340;[3764, 7525, 11286, 11300, 11314, 11328, 84, 11331];11331 < 11340.git diff --check— pass.scripts/check_docs_governance.py --check— 247 documents clean after current-main integration.src/lingtai/kernel/ANATOMY.mdcitesmeta_block.py:4102-4118while the file is shorter. This PR does not expand scope to repair that pre-existing main issue.Local pytest was intentionally not run: the actual runtime environment has no pytest, and under the current no-deletion boundary pytest's basetemp retention may clean earlier paths. No automatic
pull_request/pushworkflow exists in this repository, so there is no PR CI run to describe as green.Current-main and overlap state
The branch was non-force synchronized with then-current main
630ead4a313b789cf7a25cf015d2cf41ce42ab93; that commit is the second parent of exact reviewed headc6a2d87b6e287ed6d60d6d470182a5c64452a5cf.During Opus v2 review, main advanced to
93a700279adf6b4025cac3be9e8d36c9edcd5bb8via #932. Its six changed paths have zero overlap with this PR's nine paths. A freshgit merge-tree --write-tree 93a70027 c6a2d87bis clean, result tree4e0698f3c2d421bcdf1f212de38319a5b0f90883. The PR head intentionally remains unchanged so the Opus review is still exact-head; the new main delta is covered by the clean mechanical combined-state proof.570564e55e49cb73ed8900327f4fe3624f4aa6bc: merge-tree clean in both argument orders, identical result treee32ad46a82cf5e5beae6013b9e197bb070d83480.8b475e8948e7bf04b853e052b38e81fceab7f1a7: already GitHubDIRTY; combined merge-tree conflicts in lifecycle, daemon__init__.py, andrun_dir.py. Its only direct changed-path overlap with this PR is daemon__init__.py; WIP: preserve running daemons across same-agent refresh #921 is not currently queue-ready.Final independent review
Fresh exact
claude-opus-4-8v2 review of headc6a2d87b6e287ed6d60d6d470182a5c64452a5cfreturned READY:[3764, 7525, 11286, 11300, 11314, 11328, 84, 11331], all< 11340;--model claude-opus-4-8;Accepted Low items:
context_token_limitvalidation, so an invalid value is ignored on a field documented as a CLI no-op rather than rejected.The nit is that projection remains a calibrated soft threshold; the 9-token test margin is an exact scale=1.0 artifact, not production tuning. None of these findings gates readiness under the stated contract. Merge authorization remains with the human.
Local execution process disclosure
Two exact-Sonnet worker runs violated the explicit no-temp/no-cleanup execution boundary even though repository state remained intact:
/tmpscratch despite reporting no cleanup; durable daemon events, not prose, are the source of truth;/tmp/run_one_test.py,/tmp/run_one_test_keep3.py, and/tmp/run_one_test_verbose.py;/tmp/anatomy_base.md,/tmp/anatomy_main.md, and/tmp/main_target_lines.txtdespite a no-temp instruction.No tracked or untracked repository deletion was observed. These process deviations do not count as product validation and are disclosed rather than hidden.
Scope boundary
This PR remains open for review. It does not merge, release, tag, deploy, or change authentication/configuration. No issue is closed by this body.