Skip to content

fix(opencode): defer defaultAgent lookup in session summarize#36363

Open
1837620622 wants to merge 1 commit into
anomalyco:devfrom
1837620622:fix/compact-defer-default-agent
Open

fix(opencode): defer defaultAgent lookup in session summarize#36363
1837620622 wants to merge 1 commit into
anomalyco:devfrom
1837620622:fix/compact-defer-default-agent

Conversation

@1837620622

Copy link
Copy Markdown

Issue for this PR

Closes #29277

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

/compact (and POST /session/:id/summarize) silently fails when default_agent is configured as a subagent.

Root cause (still on dev):

const defaultAgent = yield* agentSvc.defaultAgent()  // throws if subagent
const currentAgent = messages.findLast(...)?.info.agent ?? defaultAgent

Agent.defaultAgent() throws "default agent X is a subagent" before the last user-message agent fallback is considered. The TUI often ignores the API error, so compaction appears to do nothing.

Minimal fix: only resolve defaultAgent() when the session has no user-message agent:

const lastUserAgent = messages.findLast(...)?.info.agent
const currentAgent = lastUserAgent ?? (yield* agentSvc.defaultAgent())

When the session already has a valid agent (normal case after chatting), /compact works even if default_agent is a subagent. Empty sessions still surface the config error.

Source evidence

  • packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts — eager defaultAgent() in summarize
  • packages/opencode/src/agent/agent.tsdefaultInfo throws when mode === "subagent"

How did you verify your code works?

Author

  • GitHub: @1837620622 (传康Kk)
  • Commit email: 35034498+1837620622@users.noreply.github.com (GitHub-verified noreply)

Checklist

  • Linked issue (Closes #29277)
  • No unrelated changes

/compact (POST summarize) always called Agent.defaultAgent() before
falling back from the last user message agent. When default_agent is a
subagent that call throws, so compaction fails silently even though the
session already has a valid agent.

Only resolve defaultAgent when no user-message agent is present.

Closes anomalyco#29277
@1837620622

Copy link
Copy Markdown
Author

Review ping 🙏

/compact no longer throws when default_agent is a subagent if the session already has a user agent (#29277). Checks green.

@1837620622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/compact command silently fails when default_agent is a subagent

1 participant