-
Notifications
You must be signed in to change notification settings - Fork 0
feat(sessions): add session_id FK to link agent_sessions to session logs (Phase 1 of #1668) #1812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OAGr
wants to merge
5
commits into
main
Choose a base branch
from
claude/session-id-fk-consolidation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−22
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
89a36e8
feat(sessions): add session_id FK to link agent_sessions to session logs
OAGr aef12cf
fix(ci): exclude adding-foreign-key-constraint squawk rule
OAGr e800b18
fix: rebase onto main + address CodeRabbit review feedback
OAGr 4f53fed
feat(pr-patrol): resolve CodeRabbit threads after successful fix
OAGr b501f76
fix(agent-sessions): enforce FK in test mock, fix DrizzleQueryError c…
OAGr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
apps/wiki-server/drizzle/0063_add_session_id_to_agent_sessions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- Add session_id FK to agent_sessions, linking live tracking records to their | ||
| -- corresponding historical session log. | ||
| -- | ||
| -- This replaces the fragile branch-name join currently used by the Agent Sessions | ||
| -- dashboard to enrich agent_sessions with cost/model data from the sessions table. | ||
| -- With this FK, the dashboard can use a direct JOIN instead of a heuristic match. | ||
| -- | ||
| -- The column is nullable because: | ||
| -- 1. Older records predate this migration and won't have a session_id | ||
| -- 2. Some agent sessions may never produce a session log (e.g., abandoned sessions) | ||
| -- 3. Session logs can be created after agent sessions (at PR time) | ||
| -- | ||
| -- Note: adding-foreign-key-constraint is excluded in .squawk.toml because Drizzle's | ||
| -- migrator runs in a single transaction, making the two-step NOT VALID / VALIDATE | ||
| -- pattern impossible. agent_sessions is a small table (hundreds of rows), so the | ||
| -- brief SHARE ROW EXCLUSIVE lock is acceptable. | ||
|
|
||
| ALTER TABLE "agent_sessions" ADD COLUMN IF NOT EXISTS "session_id" bigint REFERENCES "sessions"("id") ON DELETE SET NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS "idx_as_session_id" ON "agent_sessions" ("session_id"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 12038
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 16787
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 1767
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 477
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 1299
🏁 Script executed:
Repository: quantified-uncertainty/longterm-wiki
Length of output: 1801
🌐 Web query:
postgres-js error handling SQLSTATE code property💡 Result:
In postgres-js (the
postgres/ Postgres.js library), PostgreSQL server errors are thrown as aPostgresErrorwhere the SQLSTATE is available on:error.code→ the 5-character PostgreSQL SQLSTATE (e.g.23505for unique violation). [1]Example:
Notes:
codefor some client/connection errors, but those may be non-SQLSTATE strings likeUNDEFINED_VALUE,CONNECT_TIMEOUT, etc. [1]Sources:
[1] Postgres.js error handling docs (PostgresError fields incl.
codeas SQLSTATE) (tessl.io)[2] PostgreSQL error codes (SQLSTATE) documentation (postgresql.org)
Citations:
🌐 Web query:
PostgreSQL SQLSTATE 23503 foreign key violation💡 Result:
SQLSTATE
23503in PostgreSQL meansforeign_key_violation: a statement would break a FOREIGN KEY constraint. [1]It typically happens in two cases:
DETAIL: Key (...)=(...) is not present in table ...). [2]ON DELETE/ON UPDATEaction likeRESTRICT/NO ACTION/CASCADE/SET NULL/SET DEFAULT). [2]How to fix
ON DELETE CASCADE(delete children automatically),ON DELETE SET NULL/SET DEFAULT,RESTRICT/NO ACTIONand delete/update children explicitly first. [2]SET CONSTRAINTS ... DEFERRED). [2]Quick diagnosis tip: the error message includes the constraint name (e.g.,
... violates foreign key constraint "child_parent_id_fkey"). Use that to find the exact FK definition in your schema.Sources: PostgreSQL error code
23503=foreign_key_violation[1]; PostgreSQL docs on foreign keys and referential actions (and deferrable checking) [2].[1] PostgreSQL Documentation: “PostgreSQL Error Codes” (SQLSTATE
23503)[2] PostgreSQL Documentation: “Constraints” (Foreign keys,
ON DELETE/ON UPDATE, deferrable checking)Use
error.code === "23503"instead of parsingerror.messagefor FK violations.The
postgreslibrary exposes PostgreSQL error codes onerror.code(the 5-character SQLSTATE). For foreign key violations, this is"23503". The current string-matching approach is fragile and may fail if the error message shape changes; this codebase already uses the.codeproperty pattern instatements.ts(lines 1397–1404).Replace the message check:
with:
🤖 Prompt for AI Agents