Skip to content

Chats: context window meter and compaction, after T3 Code - #60

Merged
ehonis merged 1 commit into
mainfrom
sync/private-main
Nov 17, 2026
Merged

ehonis merged 1 commit into
mainfrom
sync/private-main

Conversation

@ehonis

@ehonis ehonis commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Published from the private repository by oss-sync.

  • Chats: context window meter and compaction, after T3 Code

44 files changed, 2229 insertions(+), 78 deletions(-)

Published from the private repository by oss-sync.

- Chats: context window meter and compaction, after T3 Code

 44 files changed, 2229 insertions(+), 78 deletions(-)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T03:31:39.123453Z bd8130d PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ehonis
ehonis merged commit e77d77f into main Nov 17, 2026
4 checks passed
@ehonis
ehonis deleted the sync/private-main branch November 17, 2026 03:26

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

Copy link
Copy Markdown

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: bd8130da81

ℹ️ 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".

Comment thread web/src/chat/context.ts
Comment on lines +111 to +113
const ctx = latestContext(messages, input.provider)
if (!ctx || ctx.used < COMPACTION_MIN_TOKENS || !ctx.at) return null
return input.now - ctx.at >= (ctx.cacheTtlMs ?? CACHE_TTL_FALLBACK_MS) ? ctx.used : null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor the recorded cache expiry when offering compaction

When Claude reports a cache lifetime, cacheExpiresAt is calculated from the request start, but this check instead adds that lifetime to ctx.at, which is recorded when the usage event arrives. For a long-running response—especially one exceeding a 5-minute cache TTL—the cache can already be cold while the Compact chip remains unavailable for another full TTL. Compare now with cacheExpiresAt when present, retaining the 70-minute fallback only when expiry is unknown. The byte-identical mobile copy has the same issue.

AGENTS.md reference: AGENTS.md:L105-L105

Useful? React with 👍 / 👎.

Comment thread chat/subagents.mjs
Comment on lines +519 to +524
if (file && fromEnd) {
// From the start of the line being written, if the end falls mid-line.
const size = (await stat(file).catch(() => null))?.size || 0
const end = size ? await readSlice(file, Math.max(0, size - 65536), Math.min(size, 65536)) : null
const cut = end ? end.lastIndexOf(10) : -1
offset = cut >= 0 ? size - end.length + cut + 1 : size

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve current Codex records when attaching the tailer

On a resumed Codex chat, the watcher is created only after thread.started, then asynchronously finds the rollout and sets offset to its current end. If the CLI writes this turn’s token_count or compaction records before that lookup/stat completes—as can happen for fast turns—those new records are treated as old and permanently skipped, leaving the context meter or compaction divider stale. The initial boundary needs to be captured before the resumed turn can append, or records should be read and filtered by their existing startedAt timestamps.

AGENTS.md reference: AGENTS.md:L105-L105

Useful? React with 👍 / 👎.

Comment thread chat/compaction.mjs
Comment on lines +30 to +34
const t = await threads.get(threadId).catch(() => null)
if (!windowFor(t) || !(await enabled(t.provider))) return
const last = t.messages[t.messages.length - 1]
log(`idle compaction: compacting ${threadId} before its prompt cache expires`)
await startTurn({ threadId, text: '/compact', provider: t.provider, model: last.model, effort: last.effort, modelSettings: t.modelSettings }, { idle: 'beforeCacheExpires' })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reserve the chat before starting automatic compaction

If the owner sends a message just as this timer fires, both calls can pass startChatTurn’s initial chatRuns.active check before either registers a run. The thread-store mutations are serialized, so both turns are appended, but only the first subsequent chatRuns.start succeeds; the loser leaves an orphaned streaming assistant turn, and when the user request loses, the busy fallback also queues the same message again. Reserve the run before appending either turn, or make the automatic compaction start conditional under the same per-thread lock.

AGENTS.md reference: AGENTS.md:L105-L105

Useful? React with 👍 / 👎.

Comment thread bridge.mjs
Comment on lines +3258 to +3261
// Settings → Chat › Auto-compact after, as T3 passes it (CLAUDE_CODE_AUTO_COMPACT_WINDOW).
const ownWindow = normalizeAutoCompactWindow(chatSettings.autoCompactWindow)
return spawnJsonStream(account.cli, args, {
input, label, signal, timeoutMs, holds: browser?.holds, env: { ...instanceEnvironment(account), ...browserCli.env },
input, label, signal, timeoutMs, holds: browser?.holds, env: { ...instanceEnvironment(account), ...browserCli.env, ...(ownWindow ? { CLAUDE_CODE_AUTO_COMPACT_WINDOW: ownWindow } : {}) },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Let the environment override the auto-compact setting

When both CLAUDE_CODE_AUTO_COMPACT_WINDOW and the dashboard’s Auto-compact after value are set, this final spread replaces the deployment environment with the stored dashboard value. The meter resolver likewise prioritizes setting before env, so the UI consistently reports the wrong effective threshold. Only inject the dashboard value when the environment has not supplied one, as required by the repository’s configuration precedence.

AGENTS.md reference: AGENTS.md:L138-L139

Useful? React with 👍 / 👎.

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