Skip to content

refactor(agents): split AgentSession responsibilities - #107948

Merged
steipete merged 1 commit into
mainfrom
codex/refactor-agent-session
Jul 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/refactor-agent-session

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

AgentSession had grown to 3,337 lines in one module, mixed unrelated responsibilities, and required a grandfathered max-lines suppression. That made focused review and maintenance harder.

Why This Change Was Made

Split session behavior into focused internal layers for base lifecycle/events, prompting, models, inspection, compaction, extensions, execution, and tree operations. Extract shared public types and utilities, preserve the existing AgentSession entrypoint and behavior, consolidate repeated text/model-switch helpers, and remove the max-lines suppression.

AI-assisted. Maintainer-requested refactor; no linked issue.

User Impact

No user-visible behavior change. Maintainers get smaller responsibility-focused modules and a clean max-lines gate.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 15, 2026
@steipete
steipete marked this pull request as draft July 15, 2026 03:05
@steipete
steipete marked this pull request as ready for review July 15, 2026 03:05
@steipete
steipete force-pushed the codex/refactor-agent-session branch 3 times, most recently from 9b31302 to 81a0ef1 Compare July 15, 2026 03:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81a0ef1b2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

private baseSystemPromptOptions!: BuildSystemPromptOptions;
private exactBaseSystemPrompt: string | undefined;

export class AgentSession extends AgentSessionTree {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep AgentSession methods in SDK baseline

When the public openclaw/plugin-sdk/agent-sessions surface is regenerated, src/plugin-sdk/api-baseline.ts prints only a class declaration's direct declaration.members and does not flatten inherited members. After this split, the exported AgentSession class directly declares only the constructor and inherits all user-facing methods from the non-entrypoint AgentSessionTree, so the updated SDK hash blesses a baseline/docs surface that no longer records prompt, compact, setModel, etc.; future changes to those public methods can drift without the plugin SDK API check noticing. Please either keep the public facade members represented here or update the API baseline generator/export shape before accepting the new hash.

Useful? React with 👍 / 👎.

@steipete
steipete marked this pull request as draft July 15, 2026 04:25
@steipete
steipete marked this pull request as ready for review July 15, 2026 04:25
@steipete
steipete force-pushed the codex/refactor-agent-session branch 2 times, most recently from 15acb7f to 0f3b3f4 Compare July 15, 2026 04:51
@openclaw-barnacle openclaw-barnacle Bot added the channel: discord Channel integration: discord label Jul 15, 2026
@steipete
steipete force-pushed the codex/refactor-agent-session branch from 20e368d to 17ccc18 Compare July 15, 2026 04:57
@openclaw-barnacle openclaw-barnacle Bot removed the channel: discord Channel integration: discord label Jul 15, 2026
@steipete
steipete force-pushed the codex/refactor-agent-session branch from 17ccc18 to b7dda74 Compare July 15, 2026 05:21
@steipete
steipete force-pushed the codex/refactor-agent-session branch from b7dda74 to 40435eb Compare July 15, 2026 05:24
@steipete
steipete merged commit b9a837e into main Jul 15, 2026
46 checks passed
@steipete
steipete deleted the codex/refactor-agent-session branch July 15, 2026 05:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40435ebd0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return false;
}

if (this.isRetryableError(msg) && (await this.prepareRetry(msg))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move retry hooks above the prompting layer

When this commit is type-checked, AgentSessionPrompting only extends AgentSessionBase, but the retry and compaction hooks it calls here are introduced later in subclasses (AgentSessionExecution and AgentSessionCompaction). That means this.isRetryableError, this.prepareRetry, and the later this.checkCompaction/flushPendingBashMessages calls are not members of this class, so the split breaks the TS build unless these hooks are declared on an ancestor/abstract interface or the inheritance order is changed.

Useful? React with 👍 / 👎.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant