Skip to content

fix(api): return stored timestamps from remaining write paths - #1159

Merged
ericfitz merged 4 commits into
mainfrom
fix/1155-remaining-write-timestamps
Nov 12, 2026
Merged

ericfitz merged 4 commits into
mainfrom
fix/1155-remaining-write-timestamps

Conversation

@ericfitz

Copy link
Copy Markdown
Owner

Summary

Fixes #1155. Write responses (HTTP and SSE) now carry exactly the timestamps the database stores, at microsecond precision, identical to a later GET.

Approach (approved by Eric):

  • Central: GORM NowFunc (auth/db/gorm.go, now exported as db.NowFunc) truncates to microseconds.
  • Per path: each write path sets one explicit UTC microsecond instant and returns it. Map Updates key that value by Go field name (ModifiedAt, LastUsed), so autoUpdateTime doesn't inject a second instant.

Paths fixed

  • The 11 paths listed in fix: remaining write responses return untruncated or different-instant timestamps #1155:
    • addon create;
    • team and project note create, update and patch;
    • client credential create;
    • Timmy session and message SSE events;
    • threat model create (status_updated) and PUT/PATCH;
    • diagram create and update;
    • content and usability feedback create;
    • system setting Set.
  • Same defect, found by review:
    • audit rollback for all seven entity types (response and audit CurrentState carry the stored timestamps);
    • admin user PATCH;
    • admin group POST and PATCH.
  • Remaining untruncated persisted time.Now() sites in api/ and auth/.

Behavior changes

  • The threat model and diagram stores persist the caller's ModifiedAt. Every caller now stamps first: collaborative diagram ops, CellOperationProcessor and audit rollback used to write a stale or historical value.
  • Team and project note updates use Model().Updates(map) instead of Save. They return NotFound when the row is gone, and can no longer resurrect a concurrently deleted note.
  • Oracle fix: group update used the lowercase last_used key on an autoUpdateTime column with hooks enabled. gorm-oracle does not suppress its injection for that key, which yields a duplicate column (ORA-00957). It is now keyed LastUsed.
  • ThreatModel and Diagram create normalize caller timestamps.

Known limitation (documented in code): unversioned concurrent writes stamp in the handler, before the store mutex. As a result, modified_at can step back by milliseconds. Versioned (If-Match) writes are unaffected.

Verification

  • make verify: verify: OK on d310661.
  • make test-integration (PostgreSQL): 100 passed, 0 failed, 9 skipped.
  • New tests: api/write_timestamps_test.go, api/write_timestamps_collab_test.go, auth/repository/write_timestamps_test.go, auth/db/nowfunc_test.go. Each was confirmed failing before its fix, except feedback create and diagram create; those only fail on Linux, because the macOS clock has microsecond resolution.
  • Reviews:
    • oracle-db-admin: APPROVED WITH NOTES, twice, with no blocking items. A sweep found no remaining ORA-00957 key shapes.
    • Per-task and whole-branch reviews: all findings addressed.
    • security-review: no findings.
  • Oracle integration tests (make test-integration-oci) were skipped for this fix by Eric's decision.

🤖 Generated with Claude Code

https://claude.ai/code/session_011fnCFtPzfvJmmkCSfXZgqP

ericfitz and others added 4 commits November 11, 2026 22:28
Make GORM NowFunc truncate to microseconds (db.NowFunc), set one explicit
microsecond UTC instant on every write path listed in #1155 (addon,
team/project notes, client credentials, Timmy, threat model, diagram,
feedback, system settings), and pass the same value into map Updates keyed
by Go field name so autoUpdateTime does not inject a second instant.

Fixes #1155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011fnCFtPzfvJmmkCSfXZgqP
The threat model and diagram stores now persist the caller's ModifiedAt, so
callers that load an item and write it back must stamp a fresh one: collaborative
diagram operations (websocket_diagram_handler, CellOperationProcessor) and audit
rollbacks (which wrote the snapshot's historical value). Document the contract on
both update() methods.

Refs #1155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011fnCFtPzfvJmmkCSfXZgqP
The rollback response entity and the audit CurrentState carried the snapshot's
historical modified_at while the stored row held the fresh stamp. Thread the
stamped value out of rollbackThreatModel/rollbackDiagram and overlay it onto the
restored entity. Also tidy the update() doc comments and the ORA-00957 rationale
and drop two test nits.

Refs #1155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011fnCFtPzfvJmmkCSfXZgqP
…writes

Audit rollback of threat, asset, document, note and repository now reports the
timestamps the store stamped, through one shared overlay used for all seven
types; a rollback without modified_at is an error. Admin user PATCH and admin
group POST/PATCH return the stored values, and the group update keys last_used
by Go field name (ORA-00957 guard). Create paths normalize the caller's
timestamps, and the remaining untruncated persisted timestamps are truncated.

Refs #1155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011fnCFtPzfvJmmkCSfXZgqP
@ericfitz
ericfitz merged commit b70757b into main Nov 12, 2026
18 checks passed
@ericfitz
ericfitz deleted the fix/1155-remaining-write-timestamps branch November 12, 2026 05:35
ericfitz-version-bump Bot added a commit that referenced this pull request Nov 12, 2026
Folds 1 merged commit(s):
- b70757b fix(api): return stored timestamps from remaining write paths (#1159)
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.

fix: remaining write responses return untruncated or different-instant timestamps

1 participant