xonecas.io
62159
Sy

symb / commit 4b7c34e

fix: subagents use active model, instead of config default

xonecas2026-02-19 4b7c34ef76e2d333e4e106e25f7a697f137e4a45 parent a1d02a5

12 files changed

TODO.md+13−0
@@ -2,6 +2,17 @@
22
33 Timeout shouldn't interrupt subagents, this is breaking the subagent tool.
44
5+```
6+→ SubAgent(max_iterations=8, prompt=Explore `internal/delta/delta.go` and `i…, type=explore)
7+→ SubAgent(max_iterations=8, prompt=Explore `internal/tui/messages.go` focus…, type=explore)
8+→ SubAgent(max_iterations=8, prompt=Explore `internal/llm/loop.go` for perfo…, type=explore)
9+→ SubAgent(max_iterations=8, prompt=Explore `internal/store/session.go` and …, type=explore)
10+← sub-agent failed: LLM stream failed: Post "https://opencode.ai/zen/v1/chat/completions": http2: timeout awaiting response headers view
11+← sub-agent failed: LLM stream failed: zen: request failed with status 429 view
12+← sub-agent failed: LLM stream failed: zen: request failed with status 429 view
13+← sub-agent failed: LLM stream failed: Post "https://opencode.ai/zen/v1/chat/completions": http2: timeout awaiting response headers view
14+```
15+
516 ```
617 ← sub-agent failed: LLM stream failed: context deadline exceeded (Client.Timeout or context cancellation while reading body)
718 ```
@@ -21,6 +32,8 @@ exceeded while awaiting headers) view
2132 We need to be smarter and take a snapshot when the user sends a new message. And save it as a restore point
2233 instead of granularly tracking each change that happens in a turn.
2334
35+- [ ]: reasoning is not shown on some models from Zen?
36+
2437 ---
2538
2639 - [ ]: Resize input with mouse
cmd/symb/main.go+9−2
@@ -9,6 +9,7 @@ import (
99 "os"
1010 "path/filepath"
1111 "strings"
12+ "sync/atomic"
1213 "time"
1314
1415 tea "charm.land/bubbletea/v2"
@@ -73,6 +74,12 @@ func main() {
7374 }
7475 defer prov.Close()
7576
77+ // sharedProvider is the single source of truth for the active provider.
78+ // Both the TUI and SubAgentHandler read/write it so model switches are
79+ // immediately visible to sub-agents.
80+ sharedProvider := &atomic.Pointer[provider.Provider]{}
81+ sharedProvider.Store(&prov)
82+
7683 svc := setupServices(cfg, creds)
7784 defer svc.proxy.Close()
7885 defer svc.lspManager.StopAll(context.Background())
@@ -95,7 +102,7 @@ func main() {
95102 // Register SubAgent tool after obtaining the tools list.
96103 // SubAgent needs access to provider and all tools to spawn isolated sub-agents.
97104 subAgentHandler := mcptools.NewSubAgentHandler(
98- prov,
105+ sharedProvider,
99106 svc.lspManager,
100107 svc.deltaTracker,
101108 svc.shell,
@@ -133,7 +140,7 @@ func main() {
133140 }
134141
135142 p := tea.NewProgram(
136- tui.New(prov, svc.proxy, tools, providerCfg.Model, svc.webCache, sessionID, tsIndex, svc.deltaTracker, svc.fileTracker, providerName, svc.scratchpad, resumeHistory, registry, providerOpts, cfg.UI.SyntaxThemeOrDefault()),
143+ tui.New(prov, sharedProvider, svc.proxy, tools, providerCfg.Model, svc.webCache, sessionID, tsIndex, svc.deltaTracker, svc.fileTracker, providerName, svc.scratchpad, resumeHistory, registry, providerOpts, cfg.UI.SyntaxThemeOrDefault()),
137144 tea.WithFilter(tui.MouseEventFilter),
138145 )
139146 svc.lspManager.SetCallback(func(absPath string, lines map[int]int) {
go.mod+1−1
@@ -12,7 +12,7 @@ require (
1212 github.com/charmbracelet/x/exp/golden v0.0.0-20260209194814-eeb2896ac759
1313 github.com/charmbracelet/x/powernap v0.0.0-20260209132835-6b065b8ba62c
1414 github.com/rs/zerolog v1.34.0
15- github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219155140-c28731c633ea
15+ github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219161442-9af6c03957e5
1616 github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
1717 modernc.org/sqlite v1.45.0
1818 mvdan.cc/sh/v3 v3.12.0
go.sum+2−2
@@ -92,8 +92,8 @@ github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7
9292 github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
9393 github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
9494 github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
95-github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219155140-c28731c633ea h1:AXyDgqmj32TZ6AiZ97zp9VSS9H+3ADLMUk/AfiVNi6k=
96-github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219155140-c28731c633ea/go.mod h1:MK7Zno/U0BRk1/YDHKisc3ZXoQhcTyGnU9SbEuQ/c34=
95+github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219161442-9af6c03957e5 h1:43b4qYr26VazOOP3Gnp8U2Ka747l7pFZGLo1qPeavZo=
96+github.com/sacenox/go-opencode-ai-zen-sdk v0.0.4-0.20260219161442-9af6c03957e5/go.mod h1:MK7Zno/U0BRk1/YDHKisc3ZXoQhcTyGnU9SbEuQ/c34=
9797 github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=
9898 github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=
9999 github.com/sourcegraph/jsonrpc2 v0.2.1 h1:2GtljixMQYUYCmIg7W9aF2dFmniq/mOr2T9tFRh6zSQ=
internal/llm/prompts/subagent_explore.md+1−1
@@ -5,5 +5,5 @@ You are a code explorer. Your job is to find information and report back.
55 Rules:
66 - You are READ-ONLY. Do not use Edit.
77 - Use Grep to locate, Read to examine, Shell for git log/blame/diff only
8-- Report findings with file:line references
8+- Report findings with file:line:hash references
99 - Summarize what you found concisely — the parent agent will decide what to do with it
internal/mcptools/subagent.go+4−3
@@ -4,6 +4,7 @@ import (
44 "context"
55 "encoding/json"
66 "fmt"
7+ "sync/atomic"
78
89 "github.com/xonecas/symb/internal/delta"
910 "github.com/xonecas/symb/internal/lsp"
@@ -39,7 +40,7 @@ func NewSubAgentTool() mcp.Tool {
3940
4041 // SubAgentHandler handles SubAgent tool calls.
4142 type SubAgentHandler struct {
42- provider provider.Provider
43+ provider *atomic.Pointer[provider.Provider]
4344 lspManager *lsp.Manager
4445 deltaTracker *delta.Tracker
4546 sh *shell.Shell
@@ -48,7 +49,7 @@ type SubAgentHandler struct {
4849
4950 // NewSubAgentHandler creates a handler for the SubAgent tool.
5051 func NewSubAgentHandler(
51- prov provider.Provider,
52+ prov *atomic.Pointer[provider.Provider],
5253 lspManager *lsp.Manager,
5354 deltaTracker *delta.Tracker,
5455 sh *shell.Shell,
@@ -118,7 +119,7 @@ func (h *SubAgentHandler) Handle(ctx context.Context, arguments json.RawMessage)
118119 subCtx, subCancel := context.WithCancel(context.Background())
119120 defer subCancel()
120121 result, err := subagent.Run(subCtx, subagent.Options{
121- Provider: h.provider,
122+ Provider: *h.provider.Load(),
122123 Proxy: subProxy,
123124 Tools: filteredTools,
124125 Prompt: args.Prompt,
internal/tui/golden_test.go+1−1
@@ -27,7 +27,7 @@ func TestLayout(t *testing.T) {
2727
2828 for _, tt := range tests {
2929 t.Run(tt.name, func(t *testing.T) {
30- m := New(nil, nil, nil, "test-model", nil, "test-session", nil, nil, nil, "test-provider", nil, nil, nil, provider.Options{}, "vulcan")
30+ m := New(nil, nil, nil, nil, "test-model", nil, "test-session", nil, nil, nil, "test-provider", nil, nil, nil, provider.Options{}, "vulcan")
3131 updated, _ := m.Update(tea.WindowSizeMsg{Width: tt.width, Height: tt.height})
3232 m = updated.(Model)
3333
internal/tui/messages.go+0−1
@@ -165,7 +165,6 @@ func gitStatusCounts() (added int, modified int, removed int) {
165165 return added, modified, removed
166166 }
167167
168-
169168 // gitBranchCmd runs git to detect the current branch and dirty status.
170169 func gitBranchCmd() tea.Cmd {
171170 return func() tea.Msg {
internal/tui/toolview_test.go+1−1
@@ -11,7 +11,7 @@ import (
1111 // on a tool result entry opens the tool view modal.
1212 func TestToolViewModalOpensOnViewClick(t *testing.T) {
1313 initTheme("vulcan")
14- m := New(nil, nil, nil, "test", nil, "s", nil, nil, nil, "p", nil, nil, nil, provider.Options{}, "vulcan")
14+ m := New(nil, nil, nil, nil, "test", nil, "s", nil, nil, nil, "p", nil, nil, nil, provider.Options{}, "vulcan")
1515 updated, _ := m.Update(tea.WindowSizeMsg{Width: 120, Height: 40})
1616 m = updated.(Model)
1717
internal/tui/tui.go+6−3
@@ -4,6 +4,7 @@ import (
44 "context"
55 "image"
66 "regexp"
7+ "sync/atomic"
78 "time"
89
910 tea "charm.land/bubbletea/v2"
@@ -217,6 +218,7 @@ type Model struct {
217218 providerOpts provider.Options
218219 currentModelName string
219220 cachedModels []provider.TaggedModel // cached across all providers
221+ sharedProvider *atomic.Pointer[provider.Provider]
220222 // Pending tool calls: maps tool call ID → arguments for line extraction
221223 pendingToolCalls map[string]provider.ToolCall
222224
@@ -238,8 +240,8 @@ type Model struct {
238240 gitModified int
239241 gitRemoved int
240242
241- lastNetError string // Last LLM network error (truncated for display)
242- llmInFlight bool // True while an LLM turn is in progress
243+ lastNetError string // Last LLM network error (truncated for display)
244+ llmInFlight bool // True while an LLM turn is in progress
243245
244246 // Statusbar animation
245247 spinFrame int // Current braille spinner frame index
@@ -249,7 +251,7 @@ type Model struct {
249251 // New creates a new TUI model.
250252 // If resumeHistory is non-nil, the session is being resumed and messages are
251253 // loaded from the database instead of creating a fresh system prompt.
252-func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID string, db *store.Cache, sessionID string, idx *treesitter.Index, dt *delta.Tracker, ft FileReadResetter, providerConfigName string, pad llm.ScratchpadReader, resumeHistory []provider.Message, registry *provider.Registry, providerOpts provider.Options, syntaxTheme string) Model {
254+func New(prov provider.Provider, sharedProvider *atomic.Pointer[provider.Provider], proxy *mcp.Proxy, tools []mcp.Tool, modelID string, db *store.Cache, sessionID string, idx *treesitter.Index, dt *delta.Tracker, ft FileReadResetter, providerConfigName string, pad llm.ScratchpadReader, resumeHistory []provider.Message, registry *provider.Registry, providerOpts provider.Options, syntaxTheme string) Model {
253255 initTheme(syntaxTheme)
254256 sty := DefaultStyles()
255257 cursorStyle := lipgloss.NewStyle().Foreground(ColorHighlight)
@@ -313,6 +315,7 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
313315 registry: registry,
314316 providerOpts: providerOpts,
315317 currentModelName: modelID,
318+ sharedProvider: sharedProvider,
316319
317320 streamEntryStart: -1,
318321
internal/tui/update_modals.go+4−0
@@ -323,6 +323,10 @@ func (m *Model) handleModelSwitched(msg modelSwitchedMsg) tea.Model {
323323 return m
324324 }
325325 m.provider = msg.prov
326+ if m.sharedProvider != nil {
327+ prov := msg.prov
328+ m.sharedProvider.Store(&prov)
329+ }
326330 m.currentModelName = msg.modelName
327331 if msg.providerName != "" {
328332 m.providerConfigName = msg.providerName
performance_issues.md+37−0
@@ -0,0 +1,37 @@
1+# Performance issues
2+
3+Ordered by severity (most impactful first), based on investigation evidence.
4+
5+1. **Per-edit SQLite writes for undo tracking (blocking, frequent).**
6+ - `delta.Tracker.RecordModify`/`RecordCreate` hit SQLite under a mutex per edit (SELECT + INSERT), likely dominating turn time during edits.
7+ - Evidence: `internal/delta/delta.go:33-39:a0`, `internal/delta/delta.go:48-90:a0`.
8+
9+2. **Snapshotting on the LLM turn path (filesystem-heavy).**
10+ - Pre/post snapshots run inline each turn; full directory snapshotting adds latency.
11+ - Evidence: `internal/tui/messages.go:284:5a`, `internal/tui/messages.go:303:ed`, `internal/tui/messages.go:340:54-356:0f`.
12+
13+3. **Sequential tool execution + high tool round cap.**
14+ - Tool calls are executed sequentially; slow tools block the turn.
15+ - Default `MaxToolRounds = 30` can cause multiple full LLM calls per turn.
16+ - Evidence: `internal/llm/loop.go:303-355:05`, `internal/llm/loop.go:122-166:f6`.
17+
18+4. **Session save/load serialization with per-message inserts.**
19+ - Global mutex held across transaction; per-message `Exec` in loop.
20+ - Busy retry sleeps can add delay.
21+ - Evidence: `internal/store/session.go:71-85:fc`, `internal/store/session.go:96-155:fc`, `internal/store/session.go:158-199:d3`.
22+
23+5. **O(n²) string concatenation during stream accumulation.**
24+ - Content and tool args concatenated per delta, causing quadratic behavior for long outputs.
25+ - Evidence: `internal/llm/loop.go:243-246:ea`, `internal/llm/loop.go:258-295:6c`.
26+
27+6. **Per-delta UI dispatch overhead.**
28+ - One channel send per delta; can cause backpressure under high token rates.
29+ - Evidence: `internal/tui/messages.go:359:6c-365:a3`.
30+
31+7. **LSP initialization/diagnostic waits block.**
32+ - LSP init can block up to 15s per server; notify waits for diagnostics (debounce + timeout).
33+ - Evidence: `internal/lsp/manager.go:182-195`, `internal/lsp/manager.go:221-226`, `internal/lsp/client.go:144-175`.
34+
35+8. **File search overhead.**
36+ - WalkDir with per-entry stat, regex gitignore per entry, and full file scans even after `MaxResults`.
37+ - Evidence: `internal/filesearch/filesearch.go:69-126`, `internal/filesearch/filesearch.go:158-179`, `internal/filesearch/gitignore.go:73-94`.