Skip to content

Commit eae9283

Browse files
committed
feat: cache optimizations, upstream PR cherry-picks, new tools
Core cache optimizations: - Move mindContext from dynamicSystem to stableSystem (500-2000+ tokens/turn cached at BP1 for sessions with SessionMind context) - Split failureContext into stableFailures (prior turns, BP1 cached) and dynamicFailures (current turn only) using signature-based dedup - Add markLargeToolResults() pre-pass: cache_control on tool-result content parts >7000 chars (~2000 tokens), Anthropic direct + OpenRouter Claude - Fix stale parts reference bug in markLargeToolResults for multi-tool messages - Add compressImages() async pre-pass via sharp (PR anomalyco#21371): 3-phase quality->dimension->fallback compression prevents 5MB API limit errors - Session snapshot resets (resetFailureSnapshot/resetEnvDynamicSent) in cleanup - prompt_async idle race condition fix: check new messages before loop break Upstream PR cherry-picks: - PR anomalyco#21535: deterministic queued message wrapping eliminates per-turn cache miss - PR anomalyco#21492: tool evidence digest (evidence.ts) preserves context through compaction - PR anomalyco#21507: session processor single-flight summary dedup improvements - PR anomalyco#21528: prompt_async idle wakeup race condition fix - PR anomalyco#21500: Levenshtein O(min(N,M)) space with Int32Array two-row algorithm New tools (PR anomalyco#21399): - ContextUsageTool (check_context_usage): real-time token/cache usage reporting - NewSessionTool (new_session): TUI-only, abort + create new session - TuiEvent.SessionNew bus event and app.tsx handler - SDK types.gen.ts/sdk.gen.ts EventTuiSessionNew type Test infrastructure: - E2E cache tests (OPENCODE_E2E=1) verified 100% cache hit rate on T2+ - Unit tests for large-tool cache breakpoints (4 scenarios) - Fix pre-existing lsp-deps.test.ts assertion bug (LspTool in make() not all()) - Add await to all ProviderTransform.message() call sites (now async)
1 parent 21642ff commit eae9283

49 files changed

Lines changed: 10426 additions & 680 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/current-agent

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
general

.claude/escalation.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Bash": {
3+
"count": 38,
4+
"last": 1775662672
5+
},
6+
"Read": {
7+
"count": 5,
8+
"last": 1775662513
9+
}
10+
}

.claude/failure-context.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"tool": "Bash",
4+
"error_excerpt": "Exit code 1",
5+
"input_excerpt": "{\n \"command\": \"which opencode-personal && rtk ls -la $(which opencode-personal) 2>/dev/null\",\n \"description\": \"Find the opencode-personal binary\"\n}",
6+
"retries": 82,
7+
"timestamp": "2026-04-08T15:37:52Z"
8+
},
9+
{
10+
"tool": "Read",
11+
"error_excerpt": "File content (54202 tokens) exceeds maximum allowed tokens (10000). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.",
12+
"input_excerpt": "{\n \"file_path\": \"/home/hafiz/git/github.com/fairyhunter13/opencode/.githooks/install-opencode.sh\"\n}",
13+
"retries": 23,
14+
"timestamp": "2026-04-08T14:26:09Z"
15+
},
16+
{
17+
"tool": "Glob",
18+
"error_excerpt": "Ripgrep search timed out after 20 seconds. The search may have matched files but did not complete in time. Try searching a more specific path or pattern.",
19+
"input_excerpt": "{\n \"pattern\": \"install-opencode*.sh\",\n \"path\": \"/home/hafiz\"\n}",
20+
"retries": 2,
21+
"timestamp": "2026-04-08T11:27:36Z"
22+
}
23+
]

.claude/failure-patterns.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"class": "file_not_found",
4+
"count": 3,
5+
"tools": [
6+
"Agent",
7+
"Bash",
8+
"Read"
9+
],
10+
"last_error": "File does not exist. Note: your current working directory is /home/hafiz/git/github.com/fairyhunter13/opencode.",
11+
"total_retries": 8,
12+
"recovery_hint": "Verify path exists before accessing. Use Glob to find correct path."
13+
},
14+
{
15+
"class": "unknown",
16+
"count": 3,
17+
"tools": [
18+
"Bash",
19+
"Glob",
20+
"Read"
21+
],
22+
"last_error": "Exit code 1",
23+
"total_retries": 107,
24+
"recovery_hint": "Analyze error pattern and adjust approach."
25+
},
26+
{
27+
"class": "syntax_error",
28+
"count": 1,
29+
"tools": [
30+
"Bash"
31+
],
32+
"last_error": "Exit code 2\nrg: regex parse error:\n (?:jsonSchema|asSchema|tool()\n ^\nerror: unclosed group\n0 matches for 'jsonSchema\\|asSchema\\|tool('\n\nrg: regex parse error:\n (?:jsonSchema|asSchema|tool()\n ",
33+
"total_retries": 1,
34+
"recovery_hint": "Validate syntax before writing. Run linter after edits."
35+
},
36+
{
37+
"class": "test_failure",
38+
"count": 1,
39+
"tools": [
40+
"Bash"
41+
],
42+
"last_error": "Exit code 1\nFAILED: git push\n$ bun turbo typecheck\n• turbo 2.8.13\nopencode:typecheck: ERROR: command finished with error: command (/home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode) ",
43+
"total_retries": 8,
44+
"recovery_hint": "Read test output carefully. Check test expectations match implementation."
45+
}
46+
]

.claude/failures.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[
2+
{
3+
"tool": "Bash",
4+
"error": "Exit code 1",
5+
"class": "unknown",
6+
"input": "{\n \"command\": \"which opencode-personal && rtk ls -la $(which opencode-personal) 2>/dev/null\",\n \"description\": \"Find the opencode-personal binary\"\n}",
7+
"timestamp": "2026-04-08T15:37:52Z",
8+
"retries": 82
9+
},
10+
{
11+
"tool": "Read",
12+
"error": "File does not exist. Note: your current working directory is /home/hafiz/git/github.com/fairyhunter13/opencode.",
13+
"class": "file_not_found",
14+
"input": "{\n \"file_path\": \"/home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode/test/session/mcp-schema-disk-restore.test.ts\"\n}",
15+
"timestamp": "2026-04-08T15:35:13Z",
16+
"retries": 3
17+
},
18+
{
19+
"tool": "Read",
20+
"error": "File content (54202 tokens) exceeds maximum allowed tokens (10000). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.",
21+
"class": "unknown",
22+
"input": "{\n \"file_path\": \"/home/hafiz/git/github.com/fairyhunter13/opencode/.githooks/install-opencode.sh\"\n}",
23+
"timestamp": "2026-04-08T14:26:09Z",
24+
"retries": 23
25+
},
26+
{
27+
"tool": "Bash",
28+
"error": "Exit code 1\nok (nothing to stash)\nsrc/session/compaction.ts(433,36): error TS2339: Property 'variant' does not exist on type '{ id: string & Brand<\"MessageID\">; sessionID: string & Brand<\"SessionID\">; role: \"user\"; time: { created: number; }; agent: string; model: { providerID: string & Brand<\"ProviderID\">; modelID: string & Brand<...>; variant?: string | undefined; }; format?: { ...; } | ... 1 more ... | undefined; summary?: { ...; } | un...'.\nsrc/session/llm.ts(315,110): error TS2339: Property",
29+
"class": "file_not_found",
30+
"input": "{\n \"command\": \"cd /home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode && rtk git stash && bun tsc --noEmit --skipLibCheck 2>&1 | grep \\\"error TS\\\" | head -20 && git stash pop\",\n \"tim",
31+
"timestamp": "2026-04-08T13:56:15Z",
32+
"retries": 3
33+
},
34+
{
35+
"tool": "Bash",
36+
"error": "Exit code 1\nFAILED: git push\n$ bun turbo typecheck\n• turbo 2.8.13\nopencode:typecheck: ERROR: command finished with error: command (/home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode) /home/hafiz/.bun/bin/bun run typecheck exited (2)\nopencode#typecheck: command (/home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode) /home/hafiz/.bun/bin/bun run typecheck exited (2)\n ERROR run failed: command exited (2)\nerror: \"turbo\" exited with code 2\nerror: failed to push some",
37+
"class": "test_failure",
38+
"input": "{\n \"command\": \"cd /home/hafiz/git/github.com/fairyhunter13/opencode && rtk git push --force-with-lease 2>&1\",\n \"timeout\": 120000,\n \"description\": \"Force push with lease to remote\"\n}",
39+
"timestamp": "2026-04-08T13:45:02Z",
40+
"retries": 8
41+
},
42+
{
43+
"tool": "Glob",
44+
"error": "Ripgrep search timed out after 20 seconds. The search may have matched files but did not complete in time. Try searching a more specific path or pattern.",
45+
"class": "unknown",
46+
"input": "{\n \"pattern\": \"install-opencode*.sh\",\n \"path\": \"/home/hafiz\"\n}",
47+
"timestamp": "2026-04-08T11:27:36Z",
48+
"retries": 2
49+
},
50+
{
51+
"tool": "Bash",
52+
"error": "Exit code 2\nrg: regex parse error:\n (?:jsonSchema|asSchema|tool()\n ^\nerror: unclosed group\n0 matches for 'jsonSchema\\|asSchema\\|tool('\n\nrg: regex parse error:\n (?:jsonSchema|asSchema|tool()\n ^\nerror: unclosed group\n0 matches for 'jsonSchema\\|asSchema\\|tool('",
53+
"class": "syntax_error",
54+
"input": "{\n \"command\": \"rtk grep -n \\\"jsonSchema\\\\|asSchema\\\\|tool(\\\" /home/hafiz/git/github.com/fairyhunter13/opencode/packages/opencode/src/session/prompt.ts\",\n \"description\": \"Find jsonSchema, asSchema, a",
55+
"timestamp": "2026-04-08T11:01:09Z",
56+
"retries": 1
57+
},
58+
{
59+
"tool": "Agent",
60+
"error": "Agent type 'explore' not found. Available agents: general-purpose, statusline-setup, Explore, Plan, claude-code-guide, planner, compaction, explorer, memory, doc-writer, architect, test-writer, reviewer, git-ops, general, router, debugger, refactor, orchestrator, skill-creator",
61+
"class": "file_not_found",
62+
"input": "{\n \"description\": \"Investigate schema2 error in anthropic fork\",\n \"prompt\": \"Search for \\\"schema2\\\" in the @fairyhunter13/ai-anthropic fork dist files. The path is:\\n/home/hafiz/git/github.com/fairy",
63+
"timestamp": "2026-04-08T10:54:34Z",
64+
"retries": 2
65+
}
66+
]

.claude/tool-calls-default.jsonl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"hash":"386767049055fafee33beae4b9e787ad","tool":"Bash","ts":1775662758}
2+
{"hash":"83986b9b70629f31ae4476e5b0fc5ed6","tool":"Bash","ts":1775662759}
3+
{"hash":"cbf8bf6b8382d8af0ee88d10985f3708","tool":"Bash","ts":1775662769}
4+
{"hash":"203b7f59638b262f7c146c46b4491fd6","tool":"Bash","ts":1775662772}
5+
{"hash":"385ad1a75dbf1721bb5d88dc422a54be","tool":"Bash","ts":1775662775}
6+
{"hash":"17838f7aa5e4656869bb295b3535a747","tool":"Bash","ts":1775662778}
7+
{"hash":"760aba6c9f335bdde2d65aa3904d8f88","tool":"Read","ts":1775662792}
8+
{"hash":"310c7c1c49db7371efb5849f1e1960a2","tool":"Bash","ts":1775662792}
9+
{"hash":"27a8f882c1c20ae0fe331475eb802f35","tool":"Bash","ts":1775662803}
10+
{"hash":"711082eec6f4af142f674d4c10e9473a","tool":"Bash","ts":1775662808}

.claude/tool-calls-test.jsonl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"hash":"2cd76d06f3256cfad3016d67d45068c0","tool":"Agent","ts":1774978402}
2+
{"hash":"ae8fd4707e9fc90981a0e264d30ce86e","tool":"Agent","ts":1774978413}
3+
{"hash":"8a3d8b36bf17b62fea1dfc3490bd3409","tool":"Read","ts":1774978413}
4+
{"hash":"ae8fd4707e9fc90981a0e264d30ce86e","tool":"Agent","ts":1774978508}

.claude/tool-calls.jsonl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{"hash":"11e1f32c705c3dc8e210358b0f262cb3","tool":"Read","ts":1774922566}
2+
{"hash":"bd6c219760301410d3c15ec9a66731e4","tool":"Read","ts":1774922566}
3+
{"hash":"e8e43669de3499492a579563346db4e6","tool":"Grep","ts":1774922570}
4+
{"hash":"27d5bcc81661552a0f35c5cce8a11fbe","tool":"Edit","ts":1774922570}
5+
{"hash":"912e6476ce619b045fc38ac90b0eea4b","tool":"Read","ts":1774922573}
6+
{"hash":"f5997732ec6740f5db0a6663e00d6965","tool":"Read","ts":1774922574}
7+
{"hash":"7d55adb903b93c81232b850d2da11112","tool":"Grep","ts":1774922575}
8+
{"hash":"39b4d67e0567949126e52caf87243ae7","tool":"Read","ts":1774922577}
9+
{"hash":"61642f98347c23e8b6afb91192accd30","tool":"TaskUpdate","ts":1774922580}
10+
{"hash":"ee8bbc10d2e97a4ca57d257550da230d","tool":"Grep","ts":1774922582}
11+
{"hash":"f964d0deeee0652b0df7c8eed75ecb73","tool":"TaskUpdate","ts":1774922584}
12+
{"hash":"b6d2e4de01e68f60cbced2e44bb7b080","tool":"Read","ts":1774922586}
13+
{"hash":"1ea4a6b07da174cb35438a3178d59ab2","tool":"Bash","ts":1774922587}
14+
{"hash":"fd8c12bfa8f5d1c93121345749a3b700","tool":"Write","ts":1774922602}
15+
{"hash":"bd7c5b2a84dfe4238c2a15267d78a0c8","tool":"TaskUpdate","ts":1774922607}
16+
{"hash":"a90ce1a1b410b41b08daa66a641db1d2","tool":"TaskUpdate","ts":1774922610}
17+
{"hash":"2d02a89a11a35b8a78cba917978da793","tool":"Edit","ts":1774922624}
18+
{"hash":"718ef808b72daac6801a8d97d8a98560","tool":"TaskUpdate","ts":1774922628}
19+
{"hash":"2ed043fd4c5798212a5479ec672070f6","tool":"TaskUpdate","ts":1774922632}
20+
{"hash":"86416bee870f5aed05580540c7c4cf85","tool":"Write","ts":1774922660}

0 commit comments

Comments
 (0)