Unify thread metadata updates above store#22236
Conversation
5090dd5 to
bb62b0e
Compare
74caa46 to
6095e6d
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6095e6da42
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e173b815f8
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
The thread metadata rewrite made persisted TokenCount events part of the observable storage path, which exposed an existing ordering issue in a few core tests. We were emitting TokenCount as soon as token usage was computed, even when the turn still had pending tool results or user-input work to finish. Split token usage bookkeeping from TokenCount event emission so the session state can still be updated immediately, while the externally visible TokenCount event is deferred until the turn is actually complete. This keeps turn history ordered around tool continuations and avoids recording a token count before the work it describes has settled. The test updates in this commit are intentionally separate from the storage rewrite: they document the corrected event ordering and remove assertions that were depending on the old premature TokenCount timing.
ed2f967 to
03928b0
Compare
owenlin0
left a comment
There was a problem hiding this comment.
A couple of thread-store metadata edge cases I think are worth tightening up.
Make the ThreadStore contract coherent: append_items is now a raw canonical history append, and update_thread_metadata is the single metadata write API. ThreadStore implementations no longer infer metadata by inspecting appended rollout items. LiveThread now owns the live append flow. It applies the rollout persistence policy before writing JSONL history, observes the canonical items with a small ThreadMetadataSync helper, and sends the derived facts back through update_thread_metadata. ThreadManager becomes the single app-facing metadata entrypoint, routing loaded threads through LiveThread and cold threads directly to the store. LocalThreadStore preserves the local compatibility requirements inside the local implementation. SQLite, when available, receives explicit metadata updates. JSONL and name-index compatibility are still maintained for explicit metadata mutations such as rename, memory-mode, and git changes, so old rollout files and SQLite-less local storage remain readable. RolloutRecorder is reduced to local JSONL writing for thread-store appends. The shared rollout persistence policy remains in codex-rollout, but recorder no longer owns live metadata synthesis. The added thread-store README captures the new ownership boundaries for future remote and local implementations.
The metadata rewrite added git metadata collection to live thread creation and kept SessionMeta git collection in the rollout recorder. Those paths can also run with temporary working directories that are not git repositories, especially in app-server integration tests. collect_git_info may spawn git and wait for its timeout before discovering that a directory is not a repository. On slower CI platforms that extra subprocess work made unrelated app-server startup tests miss their existing deadlines. Guard the call sites with get_git_repo_root first. Non-repository directories now skip git probing and record no git metadata, while real repository working directories still collect the same commit, branch, and remote information as before. This is a focused performance/behavior fix rather than a test timeout increase.
Observed metadata updates are facts derived from a live append stream. They should refine metadata for a thread whose history already exists; they should not create a new local thread on their own. Tighten the local update path so an observed-only update for an unknown thread returns ThreadNotFound instead of fabricating SQLite metadata from the observed facts. User/API metadata mutations can still resolve the rollout first and use the existing compatibility path for cold local threads. This keeps accidental or reordered live metadata updates from creating phantom threads, and it makes the local implementation match the intended store model: history creates the thread, metadata updates describe it.
A live local thread can have a rollout path known to the live writer before the JSONL file is materialized on disk. Observed metadata updates that arrive in that window need to attach to the same path instead of trying to rediscover the thread through filesystem scans. Teach LocalThreadStore's metadata update path to consult the live writer for an active rollout path and use that path when applying observed metadata. This keeps SQLite metadata pointed at the eventual JSONL file even when the metadata update runs before the file is visible to read/list fallback code. Remote stores do not need rollout paths; this remains a local-store detail that preserves JSONL and SQLite compatibility without leaking rollout-path handling back into LiveThread.
03928b0 to
991fe4c
Compare
owenlin0
left a comment
There was a problem hiding this comment.
One small readability note on the metadata test.
a721bff to
6341d4b
Compare
owenlin0
left a comment
There was a problem hiding this comment.
just one last comment but lgtm! heroic effort, thanks for cleaning a lot of the existing mess up while doing this
Uh oh!
There was an error while loading. Please reload this page.