Skip to content

Pin the knowledge snapshot for Strict runs at reservation - #213

Merged
tzhouam merged 1 commit into
mainfrom
kb/strict-knowledge-snapshot
Sep 28, 2026
Merged

tzhouam merged 1 commit into
mainfrom
kb/strict-knowledge-snapshot

Conversation

@tzhouam

@tzhouam tzhouam commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

PR 10 of the knowledge-service redesign: Strict (and quality) runs now review with the knowledge snapshot that was active when they were reserved, and report it.

Before this change, Strict read knowledge through settings.knowledge_dir, which is always the packaged tree or a configured directory. It ignored activated snapshots, and its results didn't say which knowledge was used.

  • Pin at reservation: a new reservation records the current KnowledgeView in <run>/knowledge.json: the snapshot id, manifest tree hash, and resolved real paths (never the active symlink). Idempotent retries and reclaimed never-started reservations keep the original pin. If pinning fails, the run fails with the reason instead of staying queued forever.
  • Launch: the child's KNOWLEDGE_DIR and KNOWLEDGE_ROOT point at the pin. If the pinned snapshot has been pruned, the run is failed and never launched. Without a snapshot root, the run is pinned to the server's effective knowledge_dir (packaged, or unverified for a custom directory), with KNOWLEDGE_ROOT removed.
  • Result: build_review_result reports knowledge_snapshot and knowledge_tree_sha256 in diagnostics. The review bot records these for Strict reviews in its upcoming trace PR.

Commit hook approved; full suite and SPEC freshness pass locally.

🤖 Generated with Claude Code

Strict and quality runs read knowledge through settings.knowledge_dir, which
is always the packaged tree, so they ignored an activated knowledge snapshot.
Their results also never said which knowledge they used. A run that sits in
the queue (or is relaunched after a restart) must also not pick up whatever
became active later.

- RunService records the current KnowledgeView in <run>/knowledge.json when
  it creates a Strict or quality reservation (idempotent retries do not
  rewrite it). The record holds the snapshot id, manifest tree hash and
  resolved real paths, never the `active` symlink.
- _launch points the child's KNOWLEDGE_DIR and KNOWLEDGE_ROOT at the pinned
  snapshot. If that snapshot was pruned, the run is marked failed and never
  launched, instead of silently reviewing with different knowledge. Without a
  snapshot root, the run is pinned to the server's effective knowledge_dir
  ("packaged", or "unverified" for a custom one) with KNOWLEDGE_ROOT removed,
  so a relaunch under a newly configured root cannot report "packaged"
  while reviewing with a snapshot. Runs
  reserved before this change carry no record and keep the process default.
- build_review_result reports knowledge_snapshot and knowledge_tree_sha256 in
  diagnostics, so the review bot can record the knowledge behind every Strict
  review, as it already does for Direct plans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T14:27:47.227963Z 68400a8 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.

@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: 68400a8fb9

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

# the snapshot pinned at reservation, even if another is active now;
# a snapshot pruned since then fails the run instead of silently
# reviewing with different knowledge
if not (Path(pin["knowledge_dir"]) / "AGENTS.md").is_file():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate the pinned snapshot before launching

When a verified snapshot's file contents are modified without updating its manifest, this check still succeeds because it tests only for AGENTS.md, and the child then consumes KNOWLEDGE_DIR through raw Path/KnowledgeDocs reads rather than KnowledgeView.path(). The run can therefore review with tampered knowledge while reporting the original manifest hash; validate the pinned manifest and file hashes before launch, or route child reads through the verified view.

Useful? React with 👍 / 👎.

Comment on lines 225 to +228
run_id, created = self.reservations.reserve(
spec, owner_server_id=self.server_id, owner_server_pid=self.pid,
idempotency_key=str(spec_dict.get("idempotency_key") or ""))
if created:
if created and self._pin_or_fail(run_id):

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 Persist the pin atomically with the reservation

If the server exits after reservations.reserve() persists the queued run but before _pin_or_fail() writes knowledge.json, a later idempotent retry can reclaim the run with created=True; _pin_knowledge() then sees no existing pin and records whichever snapshot is active at retry time. This violates the reservation-time binding specifically in the restart scenario the durable queue supports, so the pin must be part of reservation persistence or a reclaimed pinless post-change run must fail rather than be repinned.

Useful? React with 👍 / 👎.

@tzhouam
tzhouam merged commit 4ff16db into main Sep 28, 2026
5 checks passed
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