Commit Graph
5 Commits
Author SHA1 Message Date
Ben Potter 61ec5accdb fix(aibridge): recognize hyphenated session-id header from newer Codex releases (#26346)
Codex prompts were showing up as one session per request in the AI
Sessions list instead of being grouped into a conversation.

## Root Cause

AI Gateway extracts the Codex session key from the `session_id` request
header:

https://github.com/coder/coder/blob/main/aibridge/session.go#L57-L58

Newer Codex releases renamed the header to `session-id` (hyphen) in
[`codex-rs/codex-api/src/requests/headers.rs`](https://github.com/openai/codex/blob/main/codex-rs/codex-api/src/requests/headers.rs):

```rust
insert_header(&mut headers, "session-id", &id);
```

`Header.Get` is case-insensitive but not underscore/hyphen-insensitive,
so no session key is extracted and every request falls back to its own
session. Reproduced with Codex CLI 0.139.0.

## Changes

- Check `session-id` first, fall back to the legacy `session_id` for
older Codex versions
- Added test cases for the hyphenated header and precedence

## Before/After

The same three-prompt Codex conversation ("Write a haiku about
Pittsburgh" → "Now make it about Coder" → "Translate it to Spanish", via
`codex exec` + `codex exec resume --last`) against a local build.

**Before**: each prompt of the conversation lands as its own session,
Threads: 1


![before](https://raw.githubusercontent.com/coder/coder/recordings/recordings/codex-session-grouping/before.jpg)

**After**: the conversation is a single session with Threads: 3


![after](https://raw.githubusercontent.com/coder/coder/recordings/recordings/codex-session-grouping/after.jpg)

Clicking into the session shows all three threads on the session
timeline:

![after session
detail](https://raw.githubusercontent.com/coder/coder/recordings/recordings/codex-session-grouping/after-session-detail.jpg)

Linear: [AIGOV-437](https://linear.app/codercom/issue/AIGOV-437)

🤖 Generated with Coder Agents on behalf of @bpmct
2026-06-12 12:25:51 -05:00
Danny Kopping 8b5e1cac08 fix(aibridge): check x-session-affinity header for OpenCode sessions (#26140)
## Summary

`X-OpenCode-Session` is only set by the OpenCode "Zen" provider. Other
providers use `x-session-affinity` instead. This change falls back to
`x-session-affinity` when `X-OpenCode-Session` is not present, so
sessions are correctly identified regardless of the provider used.

Ref: https://github.com/coder/coder/pull/26128

## Changes

- `aibridge/session.go`: Prefer `X-OpenCode-Session` (Zen), fall back to
`x-session-affinity` (other providers).
- `aibridge/session_test.go`: Add tests for precedence and fallback
behavior.

> Generated with [Coder Agents](https://coder.com) by @dannykopping
2026-06-08 17:44:13 +02:00
Danny Kopping 9afd3d0bea feat: track OpenCode sessions (#26128)
This follows #26098 by teaching AI Bridge to read OpenCode session IDs
from the X-OpenCode-Session header, so OpenCode requests are grouped
consistently in interception logs.

Adds unit and integration test coverage for the new header.

<details>
<summary>Coder Agents generated</summary>

This pull request was generated with Coder Agents assistance.
</details>
2026-06-08 10:12:03 +02:00
Danny Kopping 8aa3294f06 fix(aibridge): track Charm Crush client and session ID (#24630)
*Disclaimer: implemented by a Coder Agent using Claude Opus 4.6*

Porting https://github.com/coder/aibridge/pull/277 to coder/coder after
the [aibridge code move](https://github.com/coder/coder/pull/24190).

## Summary

Fixes client detection and session ID tracking for the [Charm
Crush](https://github.com/charmbracelet/crush) AI coding client.

## Changes

### Bug fix: User-Agent matching

The actual Crush user-agent is `Charm-Crush/{version}
(https://charm.land/crush)` (hyphenated), but `GuessClient` only checked
for `charm crush/` (space-separated). After lowercasing,
`Charm-Crush/0.2.0` becomes `charm-crush/0.2.0`, which did not match the
`charm crush/` prefix.

Now matches both formats for backwards compatibility.

### Session ID tracking

Adds an explicit `ClientCrush` case to `GuessSessionID`. Crush does not
currently send a session ID header to upstream AI providers, so this
returns `nil` (consistent with how `ClientZed`, `ClientRoo`, and
`ClientCursor` are handled).

### Tests

- Added `charm_crush_hyphen` test case for `GuessClient` using the real
user-agent format.
- Added `crush_returns_empty` test case for `GuessSessionID`.
2026-04-22 19:02:31 +02:00
Paweł Banaszewski e00e85765b chore: move aibridge library code into coder repo (#24190)
This PR merges code from `coder/aibridge` repository into `coder/coder`.
It was split into 4 PRs for easier review but stacked PRs will need to
be merged into this PR so all checks pass.

* https://github.com/coder/coder/pull/24190 -> raw code copy (this PR,
before merging PRs on top of it, it was just 1 commit:
https://github.com/coder/coder/commit/70d33f33200c7e77df910957595715f81f9bec24)
* https://github.com/coder/coder/pull/24570 -> update imports in
`coder/coder` to use copied code
* https://github.com/coder/coder/pull/24586 -> linter fixes and CI
integration (also added README.md)
* https://github.com/coder/coder/pull/24571 -> added exclude to
scripts/check_emdash.sh check

Original PR message (before PR squash):
Moves coder/aibridge code into coder/coder repository.

Omitted files:

- `go.mod`, `go.sum`, `.gitignore`, `.github/workflows/ci.yml,`
`Makefile`, `LICENSE`, `README.md` (modified README.md is added later)
- `.github`, `example`, `buildinfo,` `scripts` directories

Simple verification script (will list omitted files)

```
tmp=$(mktemp -d)
echo "$tmp"
git clone --depth=1 https://github.com/coder/aibridge "$tmp/aibridge"
git clone --depth=1 --branch pb/aibridge-code-move https://github.com/coder/coder "$tmp/coder"
diff -rq --exclude=.git "$tmp/aibridge" "$tmp/coder/aibridge"
# rm -rf "$tmp"
```
2026-04-22 17:01:01 +02:00