Skip to content

fix(antigravity-cli): only infer generation timestamps against a decoded session anchor - #1202

Merged
junhoyeo merged 1 commit into
mainfrom
fix-antigravity-anchor-provenance
Aug 25, 2026
Merged

fix(antigravity-cli): only infer generation timestamps against a decoded session anchor#1202
junhoyeo merged 1 commit into
mainfrom
fix-antigravity-anchor-provenance

Conversation

@junhoyeo

Copy link
Copy Markdown
Owner

The problem

read_trajectory_meta collapsed two different things into one i64. It decoded the session created-at from trajectory_metadata_blob.#2, and when that blob was missing or would not decode it substituted the database file's mtime — then returned a single number that served both as the per-row timestamp fallback and as the trust anchor bounding the inferred agy 1.1.18 chatModel.#9.#10 reading.

#9.#10's 8-byte layout is inferred from a field dump rather than read off a real database, so every candidate reading is deliberately pinned to the containing session's lifetime before it is accepted, and session_window_ms declines to build a window when the anchor is not positive. That guard was not doing what its doc comment claimed. A file mtime is always positive, so the <= 0 check almost never fired, and inference ran against a window anchored on the last write to the file rather than on when the conversation began. It cuts both ways: an opaque payload that happens to decode near the mtime clears the window and silently re-dates a turn, while a legitimate older generation is rejected for sitting below a recent mtime. Mis-dated turns corrupt day buckets and the server-side monotonic ratchet, which has no correction path.

The change

read_trajectory_meta now returns a TrajectoryMeta that keeps the decoded created-at (Option<i64>) separate from the effective row fallback (i64, still the mtime when nothing decoded). The Option is threaded through parse_gen_metadata into generation_timestamp_ms and inferred_epoch_ms, so inference runs only when a genuine decoded created-at is present and positive. With no real anchor the #9.#10 path is skipped entirely and the row keeps exactly the fallback dating it had before the 1.1.18 layout was handled at all.

The confirmed #9.#4 Timestamp path is untouched — it returns before any of this logic and needs no anchor, and its existing "not bounded by the session window" regression test still passes unchanged.

Tests

The existing missing-anchor test only exercised anchors of 0 and -1, neither of which a real database produces, which is precisely why this went unnoticed. It now holds the row fallback positive and varies the anchor over None, Some(0), and Some(-1), so the case that actually occurs — no decoded created-at, positive mtime fallback — is covered.

New: an_mtime_only_session_anchors_no_inference drives the real SQLite path with a positive file mtime and no decodable created-at, in both shapes that produce one (the trajectory_metadata_blob table absent outright, and the table present with a blob carrying a workspace but no #2). The #9.#10 payload is a value half an hour before the file was written, and the test asserts up front that an mtime-anchored window would have accepted it, so it cannot silently stop testing anything. agy_1_1_18_rows_are_dated_per_turn_not_at_session_start remains as the positive half of the contract: with a genuine decoded created-at, per-turn inference still works end to end.

Falsified by temporarily restoring the collapsed single-timestamp behaviour: the new test failed with assertion left != right failed: an mtime is not a session start and must not anchor inference (both sides 1787684689447, i.e. the row was re-dated to the opaque payload), while all 34 other tests in the module still passed. Restoring the fix returned the suite to green.

Verification

cargo test -p tokscale-core antigravity — exit 0, 50 passed / 0 failed. cargo test -p tokscale-core — exit 0, 1899 passed / 0 failed. cargo clippy -p tokscale-core --all-targets -- -D warnings — exit 0. cargo fmt --all -- --check — exit 0.

No agy 1.1.18 database was available, so #9.#10 remains an inferred layout; this PR narrows when that inference is trusted rather than confirming the encoding.

…ded session anchor

`read_trajectory_meta` collapsed the decoded `trajectory_metadata_blob`
created-at and the file mtime into one `i64`, and that number was used both
as the per-row timestamp fallback and as the trust anchor bounding the
inferred agy 1.1.18 `chatModel.#9.#10` reading. A file mtime is always
positive, so the `session_timestamp <= 0` guard that was supposed to decline
inference without an anchor almost never fired: databases with a missing or
undecodable metadata blob ran inference against a window built on the last
write to the file. An opaque payload decoding near the mtime was accepted,
and a genuine older turn was rejected for sitting below it.

Report the created-at as `Option<i64>` alongside the effective fallback and
thread it through `parse_gen_metadata` into `generation_timestamp_ms` and
`inferred_epoch_ms`. With no decoded created-at the `#9.#10` inference is
skipped entirely and the row keeps the fallback dating it had before the
1.1.18 layout was handled. The confirmed `#9.#4` Timestamp path returns
before any of this and is unchanged.

The existing missing-anchor test only passed 0 and -1, neither of which a
real database produces. Adds an end-to-end SQLite test covering both shapes
that yield no created-at (table absent, and a blob carrying no `#2`) with a
payload the old mtime-anchored window would have accepted.

Constraint: `#9.#10`'s 8-byte layout is inferred from a field dump, not read off a real database, so an accepted reading must be corroborated
Rejected: Keep one i64 and sentinel the mtime case | any in-band sentinel is a valid epoch-ms value
Confidence: high
Scope-risk: narrow
Directive: `session_window_ms` must only ever be handed a decoded created-at; do not reintroduce the mtime as an anchor
Not-tested: a real agy 1.1.18 database (none available; `#9.#10` remains inferred)
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Aug 25, 2026 7:37pm

Request Review

@junhoyeo
junhoyeo merged commit 151211f into main Aug 25, 2026
21 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