Summary
Magic Context can mutate an active OpenCode task invocation and truncate its prompt before the child session receives it. The child then receives only the first five characters followed by ...[truncated].
Observed child prompt:
This is prompt corruption, not ordinary historical context compaction.
Environment
- OpenCode
1.18.4
@cortexkit/opencode-magic-context 0.33.0
- Windows
- AFT disabled during a reproducing run
- Magic Context is managing context with OpenCode compaction disabled
Reproduction
- Use a long-running OpenCode session with Magic Context enabled.
- Dispatch a subagent with a prompt whose serialized task input is over 500 characters.
- Let Magic Context run a reclaim/transform pass while the task part is still pending or running.
- The child session can receive a prompt reduced to the first five characters plus
...[truncated].
The failure is intermittent because it depends on reclaim eligibility and timing. Large prompts that do not coincide with an eligible active task part are unaffected.
Root Cause
In packages/plugin/src/hooks/magic-context/tool-drop-target.ts, extractToolCallObservation() currently classifies every OpenCode part shaped like:
{ type: "tool", callID, state: { status: "running", input, output } }
as a result. Therefore the tool-call index sets hasResult = true while the invocation is still active. truncateToolPart() then calls truncateInputValues() on the live state.input, which changes long strings to:
Proposed Fix
- Classify OpenCode
pending and running tool parts as invocations.
- Treat any tool-call entry containing an active OpenCode part as incomplete and block
drop(), truncate(), and editMarker() for that entry.
- Block
setContent() from rewriting active entries or reporting a successful dropped-content mutation.
- Add defensive guards so the individual truncation and edit-marker helpers never mutate active OpenCode tool parts.
- Preserve the existing behavior for completed and unspecified-status parts and for other wire formats.
I have a local patch with focused regression tests covering active classification, the defensive guard, and completed-tool truncation.
Summary
Magic Context can mutate an active OpenCode task invocation and truncate its prompt before the child session receives it. The child then receives only the first five characters followed by
...[truncated].Observed child prompt:
This is prompt corruption, not ordinary historical context compaction.
Environment
1.18.4@cortexkit/opencode-magic-context0.33.0Reproduction
...[truncated].The failure is intermittent because it depends on reclaim eligibility and timing. Large prompts that do not coincide with an eligible active task part are unaffected.
Root Cause
In
packages/plugin/src/hooks/magic-context/tool-drop-target.ts,extractToolCallObservation()currently classifies every OpenCode part shaped like:as a
result. Therefore the tool-call index setshasResult = truewhile the invocation is still active.truncateToolPart()then callstruncateInputValues()on the livestate.input, which changes long strings to:Proposed Fix
pendingandrunningtool parts as invocations.drop(),truncate(), andeditMarker()for that entry.setContent()from rewriting active entries or reporting a successful dropped-content mutation.I have a local patch with focused regression tests covering active classification, the defensive guard, and completed-tool truncation.