Skip to content

feat: finalize Codex threads 30 minutes after they go quiet - #86

Merged
Wynelson94 merged 1 commit into
mainfrom
feat/codex-finalizer
Sep 7, 2026
Merged

feat: finalize Codex threads 30 minutes after they go quiet#86
Wynelson94 merged 1 commit into
mainfrom
feat/codex-finalizer

Conversation

@Wynelson94

Copy link
Copy Markdown
Owner

What

Codex threads now get the full pipeline — embeddings, episodes, project inference — on their own, once the rollout has been untouched for 30 minutes (DEFAULT_FINALIZE_AFTER_SECONDS = 1800). It is the Codex twin of Claude Code's SessionEnd hook: Codex sends no session-end signal, so quiet stands in for it.

Why

Seen live on 2026-09-07: codex-sync --semantic embedded 5 threads; within a minute the active thread grew, the 60-second poller re-captured it exact-record-only, and its stage regressed to archived. Nothing ever indexed it again. Live capture already mirrored Claude's Stop hook; the SessionEnd half was missing.

How

  • scan_codex_sessions(min_idle_seconds=…) adds a settling bucket for rollouts written more recently than the bound; sync_codex passes it through and reports it. None keeps live capture unchanged.
  • finalize_codex(sqlite, codex_home, build_store) scans for quiet, un-analyzed rollouts (stat calls only) and calls build_store only when one exists — so the every-minute poller never loads the embedding model unless a thread is waiting. One thread per run.
  • codex-sync runs it after the exact-record pass by default (--finalize-after SECONDS, --no-finalize); --semantic unchanged. The shipped LaunchAgent template needs no change.
  • reconcile --fix clears the whole quiet backlog under its own lock (it already holds the model); the report and MCP tool gain codex_unfinalized / codex_settling / codex_finalized.
  • doctor: "Codex sessions archived" becomes "Codex finalizer" — green while archived threads are still being written, yellow only when one has been quiet past the bound and nothing finalized it.
  • A finalized thread that resumes is captured exact-only again and finalized again once it settles: one re-embed per resume.

Tests

8 new in tests/test_codex.py (scan bucket; finalizer waits, runs, and recovers after a resume; reconciler with a real store; CLI never loads the model while threads settle; CLI finalizes + --no-finalize; doctor row; reconcile output). 588 passing; ruff, format, mypy clean. README test badge 580 → 588 (enforced by test_surface_consistency).

Docs: docs/codex.md, README "Works with Codex", CLAUDE.md Codex note, CHANGELOG [Unreleased].

🤖 Generated with Claude Code

https://claude.ai/code/session_01PPdAP75f7yqXQwmFUtjuVM

Codex threads now get the full pipeline — embeddings, episodes, project
inference — on their own, once the rollout has been untouched for
DEFAULT_FINALIZE_AFTER_SECONDS (1800). It is the Codex twin of Claude Code's
SessionEnd hook: Codex sends no session-end signal, so quiet stands in.

Before this, an active thread indexed with `--semantic` regressed to
exact-record-only the moment it grew (the poller re-captured it as
`archived`) and nothing ever indexed it again.

- `scan_codex_sessions(min_idle_seconds=…)` adds a `settling` bucket for
  rollouts written more recently than the bound; `sync_codex` passes it
  through and reports it.
- `finalize_codex()` scans for quiet, un-analyzed rollouts and only then
  builds the LonghandStore, so the every-minute poller never loads the
  embedding model unless a thread is waiting; one thread per run.
- `codex-sync` runs it after the exact-record pass (`--finalize-after`,
  `--no-finalize`); `--semantic` is unchanged. The installed LaunchAgent
  needs no change.
- `reconcile --fix` clears the whole quiet backlog under its own lock;
  the report gains codex_unfinalized / codex_settling / codex_finalized.
- doctor: "Codex sessions archived" becomes "Codex finalizer" — green while
  archived threads are still being written, yellow only when one has been
  quiet past the bound and nothing finalized it.

Tests: 8 new (scan bucket, finalizer wait/run/resume, reconciler, CLI
model-load guard, CLI finalize + opt-out, doctor row, reconcile output);
588 passing, ruff/format/mypy clean.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPdAP75f7yqXQwmFUtjuVM
@Wynelson94
Wynelson94 merged commit c4a65e5 into main Sep 7, 2026
12 checks passed
@Wynelson94 Wynelson94 mentioned this pull request Sep 8, 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