Skip to content

feat(core): tag session http hooks with request kind - #47214

Merged
rekram1-node merged 2 commits into
v2from
session-hooks
Sep 4, 2026
Merged

rekram1-node merged 2 commits into
v2from
session-hooks

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

Adds a kind field to the session.http.request and session.http.response plugin hooks identifying which Session flow issued the request:

  • "session" — agent loop step (runner/llm.ts)
  • "compaction" — checkpoint summary (compaction.ts)
  • "title" — title generation (title.ts)
  • "generate" — transient Session.generate (generate.ts)

Previously plugins inferred purpose from event.agent (e.g. agent === "title"), which coupled them to hidden agent IDs and could not distinguish Session.generate from the loop at all. kind is a required field on PrepareInput, so every caller of SessionModelRequest.prepare must declare its flow.

The GitHub Copilot plugin switches its X-Interaction-Type classification to kind.

Naming follows Codex's per-request request_kind (turn | prewarm | compaction | memory), which is the closest analogue: per-request, delivered to hooks, distinct from thread-level source/ownership.

Scope

Deliberately limited to the HTTP hooks. context, model.request, and retry are unchanged; a follow-up will introduce a session.request hook for model/variant/sampling mutation and fold model.request into it.

Tests

  • New session-model-request-hooks.test.ts drives prepare for all four kinds and asserts both HTTP hooks observe the correct kind.
  • Copilot tests now assert classification is by kind, not agent, and that generate stays unclassified.

Session http.request and http.response hooks now carry a `kind` field
("session" | "compaction" | "title" | "generate") identifying which
flow issued the request. Plugins previously had to infer purpose from
the agent ID, which could not distinguish generate from the loop and
coupled hooks to hidden agent names.

The GitHub Copilot plugin switches its X-Interaction-Type classification
to the new field.
@rekram1-node
rekram1-node merged commit 46458f0 into v2 Sep 4, 2026
7 of 8 checks passed
@rekram1-node
rekram1-node deleted the session-hooks branch September 4, 2026 04:51
rekram1-node added a commit that referenced this pull request Sep 7, 2026
Compaction runs with the session agent; request hooks distinguish it by
kind since #47214, so the fake agent had no consumers left.
rekram1-node added a commit that referenced this pull request Sep 9, 2026
Session request hooks share a base shape: sessionID, model, system,
messages, and an options bag. The bag replaces the separate generation
and providerOptions fields; typed keys are the protocol-neutral
generation settings and any other key is passed to the protocol as a
provider option. Core partitions them when it builds the request.

Title generation gets its own hook. It is not an agent conversation, so
the event carries no agent or tools. Setting result on the event skips
the model request and uses that title.

SessionModelRequest exposes one entry per session flow: primary,
compaction, generate, and title. Each runs the hook that shapes its flow
and sets the request kind, so callers no longer pass kind, contextHooks,
or contextAgentID. Compaction requests report the session agent on every
hook; kind distinguishes them since #47214, so the fake compaction agent
had no consumers left.
rekram1-node added a commit that referenced this pull request Sep 9, 2026
Session request hooks share a base shape: sessionID, model, system,
messages, and an options bag. The bag replaces the separate generation
and providerOptions fields; typed keys are the protocol-neutral
generation settings and any other key is passed to the protocol as a
provider option. Core partitions them when it builds the request.

Title generation gets its own hook. It is not an agent conversation, so
the event carries no agent or tools. Setting result on the event skips
the model request and uses that title.

SessionModelRequest exposes one entry per session flow: primary,
compaction, generate, and title. Each runs the hook that shapes its flow
and sets the request kind, so callers no longer pass kind, contextHooks,
or contextAgentID. Compaction requests report the session agent on every
hook; kind distinguishes them since #47214, so the fake compaction agent
had no consumers left.
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
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.

1 participant