Repository navigation
fix(history): isolate consolidation sessions - #19733
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The new Not justified as shipped
What this change shipsInventory (7 items) — 3 justifiedIntent: stop long history consolidation from making cron and maintenance background jobs wait. FIX (#19731).
[FIRST-PRINCIPLES-REVIEWED] 2e130de Description read[DESCRIPTION-READ] c52214c6877c6b5032c7f80fa72ba9098f344e1f7a8342bd8b409ca213a0e5eb That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that context overflow still recycles [DESIGN-REVIEWED] 2e130de Description read[DESCRIPTION-READ] 2485e9a0f98ff6e484f1a4f604d960cb1a26c48b5d81005530e05cb20b011799 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
f8d85ac to
479772c
Compare
buluoray
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES (head 479772c86d)
What it fixes
History extraction ran on the shared _bg session, so a long extraction turn held _bg's semaphore and every short background job (titles, link previews, dedupe judges) queued behind it. Extraction now gets its own lazily created _consolidate session; cheap judges stay on _bg. Root-cause fix, not a timeout bump.
What I verified
history_consolidation.py:4370-4377passessession_key=CONSOLIDATE_KEY;llm_helpers.py:2480selects it and:2586-2591recycles that key with its own agent, while_bgkeeps the oldrecycle_background()call.session_allocation.py:2341andsession_lifecycle.py:3291,3317treat_consolidateas stateless by exact key, so it never resumes from or writes the session map. Nothing persisted changes shape: history offsets, daily files and the session map load exactly as before on upgrade, and V2memory-consolidation:cleanup is untouched.- Containment does not widen:
governance_profiles.py:1428keeps_consolidatean unproven, unattended identity like_bg, andsel.py:3560still classifies it asbackground, matching what these turns were recorded as before. - Idle expiry:
_consolidateis deliberately outside_PERSISTENT_KEYS(session.py:806). The held turn semaphore protects an active turn, andtest_active_consolidation_survives_idle_sweeppins it. Error paths fail closed: a failed acquire still raises_ConsolidationNotDispatchedand sends nothing. - Targeted suites pass: 888 passed. Mutations: dropping the
stateless_keyscheck reddenstest_consolidation_expires_and_recreates_without_resume. Forcingbackground_turnback onto_bgreddenstest_active_consolidation_survives_idle_sweep,test_dedicated_key_owns_its_session_and_recycleandtest_extraction_and_cheap_judge_use_separate_keys.
Blocking
docs/system-specs/modules/session.md:4961contains a stray commit-log line,ebb643681 (fix(history): isolate consolidation sessions), in the middle of the session-key table. It ends the table, so the Lesson extract, Subagent and TaskRunner rows below it no longer render as a table. Fix: delete that line.
Non-blocking follow-ups
- No test covers
_consolidatein theidentity_provenexclusion: removing it fromgovernance_profiles.py:1428keeps 1443 governance tests green. Add aresolve_active_scope("_consolidate", <unattended surface>)deny-all assertion. - Other
_bgexact-key sites were not extended:taskq/lanes.py:31(_SYSTEM_KEYS),validation.py:398(infer_use_casenow returnsunknown, which is the more restrictive answer),context_assembly/sections.py:74, anddashboard/session_memory.py:316(shows the raw key as the title). None of these has a reachable effect today as far as I traced, but each is a place where the new key quietly falls into a default. - The
test_agent_panel_crew_log.pyandtest_eval_harness.pyrewrites have nothing to do with this change. The eval-harness tests now call the private_run_turninstead ofrun_scenario, which narrows what they exercise. Please justify this in the description or split it into a separate PR.
Not verified
- I did not measure real-provider memory with the extra resident lite process, and did not check behaviour on runtime-capable backends (
_bg_backend_supports_runtime).
Fixes #19731 Co-authored-by: Premshay <28099628+Premshay@users.noreply.github.com>
The wait-discipline ratchet forbids a new wait_for under 30s; the guard only names a hang, so the longer ceiling keeps its meaning. Co-authored-by: Premshay <28099628+Premshay@users.noreply.github.com>
479772c to
2e130de
Compare
|
@buluoray Thanks. The blocking item is fixed on head
The fix is amended into the first commit. The second commit is unchanged, and no code changed. |
|
@buluoray your change request is the only thing holding this PR. @iamwhatever says it is addressed on head Posted by an AI assistant at bolichen97's request. |
buluoray
left a comment
There was a problem hiding this comment.
Re-review at 2e130de. This supersedes my earlier request changes.
My blocker is fixed: the stray ebb643681 (fix(history): isolate consolidation sessions) line is gone from docs/system-specs/modules/session.md, so the table below it renders again. Range-diff against the head I reviewed shows that line as the only change to the fix commit; the test commit is unchanged.
CI: 87 passed, 14 skipped, 0 failed.
…0463) Every global consolidation job shared the "_consolidate" conversation, which was replaced only at 70% context or 40 prompts. One job is ~80 KB, so a conversation stacked 40+ jobs: small-window models refused the prompt and 1M-window models drew HTTP 429. The backend record of each conversation (KAS sess_<id>) was never deleted. - _call_llm mints a fresh "_consolidate:<uuid4 hex>" key per job; background_turn removes and destroys that session in a finally, on success or failure, instead of recycling it. - A one-job provider (global or member path) is asked to delete its backend record at shutdown: the harness teardown for that session id runs before the runtime kill (KAS _kiro/session/delete; kiro-cli terminate plus the guarded cli transcript unlink). - The job key is stateless; every job works in the shared "_consolidate" directory, so a job leaves no directory of its own. - Global jobs still run one at a time and never take _bg (#19733). - Usage rows stay under "_consolidate"; telemetry, audit-source and governance classify a job key like the shared key. - The consolidation failure log names the served model and prompt size. - The fake ACP backend gains an opt-in native-store emulation, used by a real-child-process test of two back-to-back jobs. - RFC: docs/request-for-change/rfc-consolidation-job-session.md
Problem / Motivation
Goal: Long history consolidation no longer makes lightweight background jobs (cron, maintenance) wait behind it.
History consolidation uses the shared
_bgsession, coupling long memory extraction to latency-sensitive background micro-jobs.Why it matters
Lightweight maintenance queues behind consolidation even though it neither needs its context nor its admission path.
Not a goal
_bgsession's behaviour for the jobs that keep using it.What changed (motivation → approach → change)
History extraction runs on its own stateless
_consolidatesession instead of_bg, so its long turns no longer hold the semaphore the background micro-jobs share;_bgbehaviour is unchanged._PERSISTENT_KEYS: idle cleanup reclaims its process like any other session, and an active consolidation turn is never expired mid-turn (its semaphore is held). Recycling after a full context recycles its own provider._TELEMETRY_EXACT_KEYSentry ("_consolidate": "consolidation"), the same table that already names_bgand_hb; no new prefix rule.Backwards compatibility
Compatible: nothing that works today stops working —
_bgsessions keep the same behaviour and admission path, andsel._infer_sourcemaps the new_consolidatekey to the samebackgroundsurface, so attribution and spend accounting are unchanged.Removes nothing: the change is additive — one new session key plus its stateless-expiry entry; no key, kind, or entry point that main accepts is renamed, rejected, or removed.
Tests
python -m pytest -q test/test_session.py test/test_background_turn_accounting.py test/metrics/test_startup_channel_attrs.py— 448 passed; the history/consolidation/session-background files — 732 passed. New coverage: the exact-key telemetry label, separate keys for extraction and the cheap judge, idle expiry and re-creation without resume, an active consolidation surviving the sweep, and recycling its own provider.Manual verification
N/A — focused automated coverage is sufficient.
Screenshots / video
N/A — backend only.
Related Issues
Fixes #19731
Replaces #9036 — original work by @Premshay, cherry-picked with authorship kept (plus a
Co-authored-by:trailer). Ported onto current main: the only conflict wasrecycle_backgroundonSessionManagerandBackgroundSessionRuntime, where main added a keyword-onlycontext_overflowedflag; the port keeps both the newsession_key/agentparameters andcontext_overflowed.Pattern harvest
Rule candidate: long-running maintenance needs a distinct admission identity from latency-sensitive background work.
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license (see CONTRIBUTING.md).