Skip to content

Record the source fingerprint in an Observation and warn when it changes - #30

Merged
yong-opus merged 3 commits into
mainfrom
yongsu/source-fingerprint
Nov 21, 2026
Merged

yong-opus merged 3 commits into
mainfrom
yongsu/source-fingerprint

Conversation

@yong-opus

@yong-opus yong-opus commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

An Observation named its source only by path. If the file at that path was re-encoded or replaced, observation query kept returning the old evidence, with no sign that its timestamps no longer matched the file.

What changes

  • observe records the source's sha256, size_bytes and modified_unix_ms under asset in manifest.json.
  • query compares size and modification time first and rehashes only when they differ. If the hash no longer matches, it prints:
    warning: clip.mp4 changed after this Observation was made (sha256 e21939863203 recorded, 942e19d40079 now). Its timestamps and evidence may not match the file; run observe again.
  • The MCP query tool adds that warning line to its result. Other stderr stays out.
  • A missing file, or an Observation made before these fields existed, produces no warning.
  • The SHA-256 helper moves from update.rs to util.rs.
  • The schema gains three optional asset fields, and the JSON schema is regenerated. The CLI reference documents the behavior.

The idea comes from VIVID's evidence memory, which keys evidence by path plus content hash.

Also: regenerated JSON schemas (commit 17f7010)

#26 bumped zod from 4.3.6 to 4.6.7, which changed its JSON Schema export: nullable fields become a type array, and date-time patterns require seconds. The committed schema/json/*.json files were not regenerated, so the schema drift check fails on any PR that runs it, including this one. This commit regenerates sample, signal_deck and observation_manifest from the lockfile.

Cost

observe reads the source once more to hash it. That is small next to the FFmpeg passes it already makes. A query on an unchanged file only runs stat.

Testing

  • cargo test --release: 119 passed, 0 failed. This includes the new source_warning_reports_a_changed_file_only, which covers no fingerprint, unchanged, touched with the same bytes, changed content, and a missing file.
  • End to end on an eval fixture: an unchanged file and a touch-only file give no warning; replacing the file with a re-encode prints the warning above.
  • The generated manifest.json validates against observation_manifest.

This PR is independent of #6, #29 and #5. It is based on main.

🤖 Generated with Claude Code

An Observation named its source only by path. If the file at that path was
re-encoded or replaced, observation query kept returning the old evidence
with no sign that its timestamps no longer matched the file.

observe now records the source's SHA-256, size and modification time under
asset in manifest.json. query compares size and modification time first and
rehashes only when they differ; if the hash no longer matches it prints a
warning to stderr, and the MCP query tool adds that warning to its result.
A missing file, or an Observation made before this field existed, stays
quiet. The idea comes from VIVID's content-hash-keyed evidence memory.

The SHA-256 helper moves from update.rs to util.rs so both use one copy.
The schema gains three optional asset fields; the JSON schema is regenerated.

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

chatgpt-codex-connector Bot commented Nov 19, 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-19T15:29:54.321492Z 0d12dd3 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.

The dependency update in #26 changed zod's export: nullable fields become
a type array, and date-time patterns require seconds. The committed JSON
schemas were not regenerated, so the schema drift check failed on any PR
that touched the schemas. This regenerates them from the lockfile.

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

@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: 0d12dd3bd2

ℹ️ 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 cli/src/workspace/manifest.rs Outdated
Comment on lines +119 to +120
let uri = asset.get("uri")?.as_str()?;
let metadata = std::fs::metadata(uri).ok()?;

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 Store an absolute source URI for later checks

When observe receives a relative video path, the probe preserves that raw argument in asset.uri, and this lookup later resolves it against the query process's current directory. Querying the Observation after changing directories—including running observation query . from inside the Observation—therefore treats an existing source as missing and silently skips the warning even if the source changed. Canonicalize the source when recording the manifest, or otherwise retain the creation-directory context.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e937f0c. The fingerprint now records the canonical absolute path in asset.path, and the check uses it before uri. Verified end to end: observe clip.mp4 by relative path, replace the file, then run observation query . --at 1 from inside the Observation. The warning is printed.

Comment thread cli/src/workspace/manifest.rs Outdated
Ok(json!({
"sha256": crate::util::sha256_file(path)?,
"size_bytes": metadata.len(),
"modified_unix_ms": modified_unix_ms(&metadata),

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 Omit unavailable modification timestamps instead of writing null

For a valid source whose modification time cannot be represented after the Unix epoch—for example, archived media with a pre-1970 timestamp—modified_unix_ms returns None, but json! serializes that as "modified_unix_ms": null. Both newly updated schemas permit this field to be absent but reject null, so observe emits a manifest that fails the advertised Observation contract. Insert the field only when a timestamp is available.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e937f0c. modified_unix_ms is now inserted only when the timestamp is available, so a pre-epoch file produces a manifest without the field instead of null.

Review findings on the fingerprint:

- observe kept the video argument as given in asset.uri, so after
  observing a relative path, a query from another directory (including
  `query .` inside the Observation) could not find the source and skipped
  the warning. The fingerprint now records the canonical absolute path in
  asset.path, and the check uses it before uri. The docs note that this
  path contains directory names.
- A modification time before the Unix epoch was written as null, which the
  schema rejects. The field is now left out when it is unknown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yong-opus
yong-opus merged commit 22655ff into main Nov 21, 2026
@yong-opus
yong-opus deleted the yongsu/source-fingerprint branch November 21, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant