Repository navigation
Subagent crashes with Request failed: session not found: ses_{sesid} #818
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Short description
Subagent historian crashes with session not found on OC2
What happened?
When a subagent is spawned by magic context historian, mid prompt processing it crashes and the subagent process no longer exists. Providing a popup on opencode 2 with request failed: session not found: ses_{sesid} context length remains the same.
Diagnostics
## Title
Subagent crashes with Request failed: session not found: ses_{sesid}
## Description
When a subagent is spawned by magic context historian, mid prompt processing it crashes and the subagent process no longer exists. Providing a popup on opencode 2 with request failed: session not found: ses_{sesid}
_Paths and IDs in diagnostic data use per-report aliases. Session titles, private package names, free-text log values, and source/tool content are omitted; fixed Magic Context diagnostic wording and safe diagnostic fields remain. Your issue title and description are shown unchanged._
## Environment
- Plugin: v0.49.29
- OS: win32 x64
- Node: v24.22.1
- OpenCode: not installed
## Configuration
Config from `~/path-4`:
{
"$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
"historian": {
"opencode": {
"model": {
"model": "ik-llama/qwen3.6-35b-a3b",
"variant": "<text omitted>"
}
}
},
"dreamer": {
"disable": true
}
}
## Diagnostics
- Timestamp: 2026-10-29T10:27:05.282Z
- Plugin: v0.49.29
- OS: win32 x64
- Node: v24.22.1
- OpenCode installed: true [desktop]
- OpenCode session database: ~/path-9 (source=<text omitted>)
- Plugin registered in opencode config: true
- Plugin registered in tui config: true
- magic-context.jsonc parse error: none
- Conflicts detected: none
- MC compaction mode: on
- Native compaction: auto=false, prune=false
### Config paths
{
"configDir": "~/path-2",
"opencodeConfig": "~/path-3",
"opencodeConfigFormat": "jsonc",
"magicContextConfig": "~/path-4",
"tuiConfig": "~/path-5",
"tuiConfigFormat": "jsonc",
"omoConfig": null
}
### magic-context.jsonc flags
{
"$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
"historian": {
"opencode": {
"model": {
"model": "ik-llama/qwen3.6-35b-a3b",
"variant": "<text omitted>"
}
}
},
"dreamer": {
"disable": true
}
}
### Plugin cache
{
"path": "~/path-6",
"cached": null,
"latest": "0.49.29",
"installs": [
{
"layout": "opencode2",
"spec": "latest",
"path": "~/path-7",
"cached": "0.49.29"
}
]
}
### Storage
- Warning: Magic Context storage is at ~/path-8, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.
{
"path": "~/path-8",
"source": "<text omitted>",
"exists": true,
"context_db_size": "1.1 MB"
}
### Recent sessions
Recent sessions: unavailable (store generation mismatch: <text omitted>)
### Historian dumps
(Metadata only — XML content is not included in this report.)
Dumps are stored per-project under `<project>/.cortexkit/magic-context/historian/`.
{
"byProject": [],
"legacyDumps": {
"dir": "~/path-13",
"count": 0,
"recent": []
}
}
### Historian failures (session_meta)
_Note: this counter RESETS to 0 on every successful run — see 'Historian runs' below for the durable history._
_No sessions with historian failures._
### Historian runs (durable telemetry)
Per-session success/failure/no-op counts from `historian_runs` (never reset).
[
{
"sessionId": "session-1",
"total": 2,
"success": 2,
"failed": 0,
"noop": 0,
"lastFailureReason": "",
"lastRunAt": "2026-10-29T10:24:43.989Z"
}
]
### Log files
- ~/path-10: exists=true, grammar=unknown, lines=105, size=12 KB
- ~/path-11: exists=false, grammar=unknown, lines=0, size=0 KB
- ~/path-12: exists=false, grammar=unknown, lines=0, size=0 KB
## Historian failure signals (log, sanitized)
_No historian failure log lines found in recent history._
## Recent errors (last 20, sanitized)
_No error-shaped log lines found in recent history._
## Log (last 400 lines, sanitized)
LOG magic-context <text omitted>
LOG magic-context <text omitted> 5000ms
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted> path-14
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted> path-15
LOG magic-context <text omitted>
LOG magic-context <text omitted> path-16
LOG magic-context <text omitted> path-17
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context failed: <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context failed: <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>
LOG magic-context <text omitted>Plugin version
0.49.29
OpenCode version
2.2.1
Platform
windows x64
Client
OpenCode Desktop
Log output (optional)
[2026-10-29T10:24:43.977Z] [magic-context][<SESSION_ID>] historian: prompt completed (attempt 1/3)
[2026-10-29T10:24:43.977Z] [magic-context][<SESSION_ID>] historian response_chars=1065 tokens=<REDACTED:tokens>"input":2510,"output":270,"reasoning":0,"cache_read":15360,"cache_write":0,"max_tokens":null,"finish_reason":"stop"}
[2026-10-29T10:24:43.978Z] [magic-context][<SESSION_ID>] compartment agent: historian response dumped {"label":"incremental-<SESSION_ID>-150-156-initial","dumpPath":"<HOME>\\Desktop\\Development\\Projects\\DeepTrace\\.cortexkit\\magic-context\\historian\\<SESSION_ID>-incremental-<SESSION_ID>-150-156-initial-1793269483978.xml"}
[2026-10-29T10:24:43.984Z] [magic-context][<SESSION_ID>] historian publish stage: stage=parse status=started elapsed=0.0ms response_chars=1065
[2026-10-29T10:24:43.984Z] [magic-context][<SESSION_ID>] historian publish stage: stage=parse status=completed elapsed=0.1ms compartments=1 dropped_fact_blocks=0 dropped_facts=0
[2026-10-29T10:24:43.984Z] [magic-context][<SESSION_ID>] historian publish stage: stage=validate status=started elapsed=0.0ms
[2026-10-29T10:24:43.984Z] [magic-context][<SESSION_ID>] historian publish stage: stage=validate status=completed elapsed=0.0ms compartments=1
[2026-10-29T10:24:43.986Z] [magic-context][<SESSION_ID>] historian publish stage: stage=dangling-boundary-check status=started elapsed=0.0ms compartments=1
[2026-10-29T10:24:43.986Z] [magic-context][<SESSION_ID>] historian publish stage: stage=dangling-boundary-check status=completed elapsed=0.2ms
[2026-10-29T10:24:43.986Z] [magic-context][<SESSION_ID>] historian publish stage: stage=post-publish-drops status=started elapsed=0.0ms range=150-156
[2026-10-29T10:24:43.987Z] [magic-context][<SESSION_ID>] historian publish stage: stage=publish-txn status=started elapsed=0.0ms
[2026-10-29T10:24:43.988Z] [magic-context][<SESSION_ID>] compartment agent: queued 7 drops for messages 150-156
[2026-10-29T10:24:43.988Z] [magic-context][<SESSION_ID>] historian publish stage: stage=post-publish-drops status=completed elapsed=2.0ms range=150-156
[2026-10-29T10:24:43.988Z] [magic-context][<SESSION_ID>] historian publish stage: stage=publish-txn status=completed elapsed=1.2ms compartments=1
[2026-10-29T10:24:43.989Z] [magic-context][<SESSION_ID>] note-nudge: trigger fired (historian_complete), triggerPending=true
[2026-10-29T10:24:43.989Z] [magic-context][<SESSION_ID>] historian publish stage: stage=embeddings status=started elapsed=0.0ms
[2026-10-29T10:24:43.989Z] [magic-context][<SESSION_ID>] historian publish completed: compartments=1 range=150-156
[2026-10-29T10:24:43.999Z] [magic-context][<SESSION_ID>] historian publish stage: stage=embeddings status=completed elapsed=10.5ms compartments=1
[2026-10-29T10:27:36.487Z] [magic-context][<SESSION_ID>] channel1 evaluation: ctx_reduce=callable U=34205 T=49396 ratio=0.6925 band=quiet grace_baseline_u=none grace_growth=0 growth_threshold=25000 sticky_floor_turns_remaining=3 dampening=baseline-hold verdict=hold reason=agent-drops-applied
[2026-10-29T10:27:36.564Z] [magic-context][<SESSION_ID>] v2 usage: inputTokens=62508 contextLimit=114688 percentage=54.50265066964286 responseModel=ik-llama/qwen3.6-35b-a3b draftContextLimit=114688 pressure=current
[2026-10-29T10:27:36.565Z] [magic-context][<SESSION_ID>] injected generic guidance into system prompt (ctxReduce=true, subagent=false, subagentReduceMode=false)
[2026-10-29T10:27:36.572Z] [magic-context][<SESSION_ID>] transform threshold: model=ik-llama/qwen3.6-35b-a3b matchedModel=scalar mode=percentage threshold=65% proactiveFloor=63%
[2026-10-29T10:27:36.572Z] [magic-context][<SESSION_ID>] transform scheduler: percentage=54.5% inputTokens=62508 cacheTtl=5m lastResponseTime=1793269656543 decision=defer
[2026-10-29T10:27:36.579Z] [magic-context][<SESSION_ID>] compartment trigger: not firing at 54.5% — below proactive floor (63%)
[2026-10-29T10:27:36.584Z] [magic-context][<SESSION_ID>] heuristics WILL NOT RUN — reason=scheduler_defer
[2026-10-29T10:27:36.584Z] [magic-context][<SESSION_ID>] pending ops WILL NOT APPLY — reason=scheduler_defer pendingOps=7 context=54.5%
[2026-10-29T10:27:36.585Z] [magic-context][<SESSION_ID>] prefix trim: boundary msg_1872aee550019L5oSHjM5La8qm precedes the first remaining message msg_1872b3ad2001BeP8159ILpZ4qB; rows between were cut with the summarized history or removed by reduction this pass; pass=defer; nothing to cut
[2026-10-29T10:27:36.585Z] [magic-context][<SESSION_ID>] transform: injected m[0]/m[1] (rematerialized=false, reason=cache_hit)
[2026-10-29T10:27:36.585Z] [magic-context][<SESSION_ID>] note-nudge: deferring — user already served or first serve unproven
[2026-10-29T10:27:36.586Z] [magic-context][<SESSION_ID>] final representation: clearedParts=0 mergedReasoningParts=0 removedReasoningParts=0 settledDroppedReasoning=0
[2026-10-29T10:27:36.588Z] [magic-context][<SESSION_ID>] transform: final-wire telemetry estimate=unavailable trusted=false conversation=unknown tools=unknown system=unknown toolDefinitions=unknown tail=[assistant:reasoning+tool, assistant:reasoning+tool, assistant:reasoning+tool]
[2026-10-29T10:27:36.589Z] [magic-context][<SESSION_ID>] channel1 evaluation: ctx_reduce=callable U=18461 T=49423 ratio=0.3735 band=quiet grace_baseline_u=none grace_growth=0 growth_threshold=25000 sticky_floor_turns_remaining=3 dampening=none verdict=hold reason=tail-below-minimum
[2026-10-29T10:27:36.589Z] [magic-context][<SESSION_ID>] transform completed in 20.0ms (19 messages, 18 targets, watermark: 150)
[2026-10-29T10:27:36.590Z] [magic-context][<SESSION_ID>] transform stages: findSessionId=0.1ms(messages=165) lkg.entryProjection=0.5ms(reused=165 retained=165 retainedBytes=914468) rawOrdinals.prepare=0.0ms(ready=true) findLastUserMessageId=0.0ms getOrCreateSessionMeta=0.4ms tagOwners.prepare=0.4ms modelChangeDetection=0.0ms schedulerAndUsage=0.0ms emergencyRecoveryBlock=0.8ms compartmentTrigger=6.3ms prepareCompartmentInjection=0.8ms injectTemporalMarkers=0.2ms tag.initFromDb=0.3ms tag.inertWhitespace=0.0ms tag.getSourceContents=0.1ms tag.loop=0.9ms tag.deriveOwner=0.1ms tag.getToolTag=0.0ms tag.assignTag=0.1ms tag.assignToolTag=0.7ms tag.saveSource=0.0ms tagMessages=1.7ms getActiveTagsBySession=0.0ms(count=18) getDroppedTagsByNumbers=0.0ms(targets=18 fetched=0) applyFlushedStatuses=0.0ms batchFinalize:flushed=0.0ms stripStructuralNoise=0.0ms(strippedParts=0) stripClearedReasoning=0.0ms(strippedParts=0) compartmentPhase=0.1ms pp.prefixPreflight=0.5ms(foldExecuted=false m1Refreshed=false) pp.passDecisions=0.5ms(pendingOps=0) batchFinalize:heuristics=0.0ms pp.setupAndOperations=1.0ms pp.replaySnapshot=0.0ms stripProcessedImages=0.1ms pp.injectM0M1=0.7ms pp.placeholderNeutralize=0.0ms pp.nudgeAndSticky=0.0ms pp.markerWireReconcile=0.0ms pp.markerReconcile=0.0ms pp.noteAndTodoSynthesis=0.1ms pp.autoSearchHint=0.2ms pp.frozenDecisions=0.0ms finalizeMessageRepresentation=0.2ms(clearedParts=0 mergedReasoningParts=0) pp.tailReads=0.1ms pp.tailMeasure=1.4ms pp.tailState=0.4ms pp.tailBaseline=1.9ms pp.tailGuard=0.0ms postTransformPhase=5.9ms slow>=100ms=[]
[2026-10-29T10:27:36.607Z] [magic-context] session backfill start session=<SESSION_ID> missing=1 model=Xenova/all-MiniLM-L6-v2
[2026-10-29T10:27:36.815Z] [magic-context] session backfill stop session=<SESSION_ID> reason=pooling metadata unavailable
[2026-10-29T10:28:28.653Z] [magic-context][<SESSION_ID>] v2 usage: inputTokens=64778 contextLimit=114688 percentage=56.48193359375 responseModel=ik-llama/qwen3.6-35b-a3b draftContextLimit=114688 pressure=currentReacted by magic-alfonso
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
magic-alfonso commentedon Oct 29, 2026
Thanks for the report and the log.
From the log, the historian run itself didn't crash: at 10:24:43 it completed on its first attempt, published one summary for messages 150-156 and queued 7 drops. After a successful run, Magic Context removes its hidden child session as normal cleanup. On OpenCode 2 that's
session.remove, which interrupts the child, waits for it to be idle, then deletes it. If OpenCode Desktop still has that child session open or is polling it when it's removed, it can report "session not found" for it. That would explain a popup with no failure in the Magic Context log.The context length not changing is expected at that point. The 7 drops are queued, and they apply on the next pass that runs cleanup. At 10:27:36 the session was at 54.5%, below its 65% execute threshold, so that pass deferred them (
pending ops WILL NOT APPLY — reason=scheduler_defer pendingOps=7).To confirm it's the cleanup and not a failing run, could you try:
"keep_subagents": true(top level) inmagic-context.jsoncand restart OpenCode. Magic Context then keeps finished child sessions instead of removing them. If the popup stops, it's the removal. Turn it back off afterwards, because kept sessions accumulate.historian publish completedlog line, and the session id it names (whether it's the historian child or your main session).Ven0maus commentedon Oct 29, 2026
I can indeed see that context length does decrease over time, so the cleanup does work indeed.
I added the keep_subagents in the root as suggested:
{ "$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json", "keep_subagents": true, "historian": { "opencode": { "model": { "model": "ik-llama/qwen3.6-35b-a3b", "variant": "quick" } } }, "dreamer": { "disable": true } }Restarted opencode 2, then reran a prompt to trigger the subtask, I saw it trigger, but request failed again soon as prompt finished in the subagent.
The first subagent crashed/stopped at 11:29:00
The second subagent crashed/stopped at 11:29:40
There is no trace of both subagent sessions in the main session (they are both gone).
I can see it also when i'm in the subagent, and it crashes, I end up on the session not found page.
When i go back to the main, there is no more subagent history to be found in that main session.
(error still appears as popup even if i don't open the subagent(s) at all)
First popup (ses_e78945821ffegy9xjMK1e7l0Ax):

Second popup (ses_e7893bdf2ffeSCoxanpgrsf6xM):

MC log:
magic-alfonso commentedon Oct 29, 2026
Thanks, that's a very useful test. It narrows things down a lot.
We matched the two session ids in your popups to Magic Context's own historian runs. Each OpenCode id carries its creation time. The two ids were created 39,471 ms apart, exactly the gap between the two
historian: creating child sessionlines in your log (11:29:01.916 and 11:29:41.387). So the popups are about the historian's hidden child sessions, not about your own subagents.With
keep_subagents: true, Magic Context's normal cleanup after a successful run should keep that child, not delete it. Since the children still vanished, either something else removes them, or the setting didn't load. We're reproducing it on a real OpenCode 2.2.1 to find out which. Two quick things would help:keep_subagentsin: your user config (%USERPROFILE%\.config\cortexkit\magic-context.jsonc) or the project one (<project>\.cortexkit\magic-context.jsonc)?ses_e78945821ffe…orses_e7893bdf2ffe…), or the wordshidden child, around those times.The summaries themselves are fine: the log shows both runs publishing, and the context shrinking afterwards.
Ven0maus commentedon Oct 29, 2026
keep_subagents was placed in the file at: %USERPROFILE%.config\cortexkit\magic-context.jsonc
I don't find any trace of any of the two mentioned session ids in the log, and no hidden child
magic-alfonso commentedon Oct 29, 2026
Thanks for checking. We reproduced part of this on real OpenCode 2.2.1, 2.2.0 and 2.1.0 (Linux, headless), using the real historian run each time.
keep_subagentsoff (the default): after the historian finishes, Magic Context removes its hidden child session as normal cleanup. A client that still holds that child then gets exactlySession not found: ses_…. That is the popup you saw at first. The summary itself is fine, as your log shows.keep_subagents: truein the user config: the child stayed in place on all three versions, still linked to its parent and readable afterwards. So we could not reproduce the children vanishing with retention on.The next release adds log lines for each hidden child: when it's created, whether it's kept or removed, and the
keep_subagentsvalue in effect at startup. After you update, the log will show exactly what happened. Until then, two things would help:npx @cortexkit/magic-context@latest doctor.keep_subagents: true, whether the children show up under the session inopencode session list(or the Desktop session list) after a historian run.magic-alfonso commentedon Oct 29, 2026
0.49.30 adds log lines for each hidden historian and dreamer child session: when it's created, whether it's kept or removed after its run, and the
keep_subagentsvalue in effect at startup.If you can update to 0.49.30, restart OpenCode, and reproduce the popup once more, please paste the Magic Context log lines around it here. Those lines will show whether the child was removed by Magic Context's cleanup or vanished some other way.