Repository navigation
fix(orchestration): call the Orca session ID orca_session_id everywhere agents see it #24230
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
Changes from all commits
f37d879
bb6ec0e
7a685db
5d8a69c
809d623
cec36b3
afad189
8031958
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { OrchestrationDb } from '../orchestration-db' | ||
|
|
||
| // Frozen literals, never the live prefix constant: a migration rewrites what that build wrote. | ||
| const LEGACY_PREFIX = 'session:' | ||
| const CURRENT_PREFIX = 'orca_session_id:' | ||
|
|
||
| // Every column an earlier build wrote a session's mail address into. Bodies, subjects and payloads | ||
| // are text, not addresses, and are left as written. | ||
| const ADDRESS_COLUMNS = [ | ||
| ['messages', 'from_handle'], | ||
| ['messages', 'to_handle'], | ||
| ['coordinator_runs', 'coordinator_handle'] | ||
| ] as const | ||
|
|
||
| // Address columns in a key: where the current spelling already has its row, the legacy one is a duplicate. | ||
| const KEYED_ADDRESS_COLUMNS = [ | ||
| ['run_coordinator_handles', 'terminal_handle'], | ||
| ['structured_pointer_operations', 'mailbox_handle'] | ||
| ] as const | ||
|
|
||
| /** | ||
| * Earlier builds addressed an Orca session as `session:<id>`. Respells every stored one as | ||
| * `orca_session_id:<id>`, so a chat still reads mail sent before the upgrade, a Run still routes | ||
| * mail to the chat that coordinated it, and a reply to old mail reaches its sender. | ||
| */ | ||
| export function migrateV43(this: OrchestrationDb, current: number): void { | ||
| if (current >= 43) { | ||
| return | ||
| } | ||
| const isLegacy = (column: string): string => | ||
| `substr(${column}, 1, ${LEGACY_PREFIX.length}) = '${LEGACY_PREFIX}'` | ||
| const respelled = (column: string): string => | ||
| `'${CURRENT_PREFIX}' || substr(${column}, ${LEGACY_PREFIX.length + 1})` | ||
| for (const [table, column] of ADDRESS_COLUMNS) { | ||
| this.db.exec(`UPDATE ${table} SET ${column} = ${respelled(column)} WHERE ${isLegacy(column)}`) | ||
| } | ||
| for (const [table, column] of KEYED_ADDRESS_COLUMNS) { | ||
| this.db.exec(` | ||
| UPDATE OR IGNORE ${table} SET ${column} = ${respelled(column)} WHERE ${isLegacy(column)}; | ||
| DELETE FROM ${table} WHERE ${isLegacy(column)}; | ||
| `) | ||
| } | ||
|
Comment on lines
+34
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
rg -nP "session:\\$\\{|'session:'|\"session:\"" src/main --type=ts -g '!**/*.test.ts' -C2
rg -nP '\b\w+_handle\b\s+TEXT' src/main/runtime/orchestration/db -C1Repository: stablyai/orca Length of output: 13181 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- migrate-v43 ---'
cat -n src/main/runtime/orchestration/db/schema/migrate-v43.ts
printf '%s\n' '--- migration references ---'
rg -n -C3 'ADDRESS_COLUMNS|KEYED_ADDRESS_COLUMNS|orca_session_id:|session:' src/main/runtime/orchestration
printf '%s\n' '--- orchestration schemas ---'
cat -n src/main/runtime/orchestration/db/schema/create-core-tables-sql.ts
printf '%s\n' '--- required diff stat ---'
git diff --stat 3ab3c9239fba5eaa36c3c4ce10aab4cf346ee812 809d6235bede57dd7dd1af990abaf73a44d7de3
printf '%s\n' '--- required diff for migration ---'
git diff --unified=30 3ab3c9239fba5eaa36c3c4ce10aab4cf346ee812 809d6235bede57dd7dd1af990abaf73a44d7de3 -- src/main/runtime/orchestration/db/schema/migrate-v43.tsRepository: stablyai/orca Length of output: 41582 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- legacy migration test fixture ---'
sed -n '600,715p' src/main/runtime/orchestration/orchestration-legacy-session-address-migration.test.ts
printf '%s\n' '--- v42 migration at head ---'
cat -n src/main/runtime/orchestration/db/schema/migrate-v42.ts
printf '%s\n' '--- relevant current address construction and consumers ---'
rg -n -C4 'ORCA_SESSION_ADDRESS_PREFIX|sessionAddress|SessionAddress|from_handle|to_handle|coordinator_handle|mailbox_handle|terminal_handle|caller_handle|recipient|owner' src/main/runtime/orchestration/db src/main/runtime/orchestration/messaging src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- legacy prefix occurrences at required base ---'
git grep -n -E 'session:|orca_session_id:' 3ab3c9239fba5eaa36c3c4ce10aab4cf346ee812 -- src/main/runtime/orchestration ':!**/*.test.ts'
printf '%s\n' '--- legacy prefix occurrences at reviewed head ---'
git grep -n -E 'session:|orca_session_id:' 809d6235bede57dd7dd1af990abaf73a44d7de3 -- src/main/runtime/orchestration ':!**/*.test.ts'Repository: stablyai/orca Length of output: 45665 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- locate legacy migration test ---'
git ls-files | rg 'legacy.*session.*address|session.*address.*migration'
printf '%s\n' '--- base v42 migration ---'
git show 3ab3c9239fba5eaa36c3c4ce10aab4cf346ee812:src/main/runtime/orchestration/db/schema/migrate-v42.ts | cat -n
printf '%s\n' '--- current test files mentioning earlier build ---'
rg -l -F 'earlier build of this step stamped v42' src/main
printf '%s\n' '--- fixture declaration and focused body ---'
file=$(rg -l -F 'earlier build of this step stamped v42' src/main | head -n1)
if [ -n "$file" ]; then
rg -n -C8 'earlier build of this step stamped v42|CREATE TABLE|CREATE TRIGGER|session:<id>|coordinator_principal|coordinator_actor|principal|actor' "$file"
fi
printf '%s\n' '--- current schema table declarations ---'
rg -n -C3 '^CREATE TABLE|coordinator_runs|dispatch_contexts|tasks|messages|deliveries|structured_pointer_operations' src/main/runtime/orchestration/db/schema src/main/runtime/orchestration/dbRepository: stablyai/orca Length of output: 45663 🏁 Script executed: #!/bin/bash
set -o pipefail
testfile=src/main/runtime/rpc/orchestration-legacy-session-address-migration.test.ts
printf '%s\n' '--- dedicated migration test address references ---'
rg -n -C6 'session:|orca_session_id:|formatOrcaSessionAddress|ADDRESS|messages|coordinator_runs|run_coordinator_handles|structured_pointer_operations|dispatch_contexts|tasks' "$testfile"
printf '%s\n' '--- address formatter uses in non-test source ---'
rg -n -C3 'formatOrcaSessionAddress|ORCA_SESSION_ADDRESS_PREFIX|structuredSessionPointerCallerKey|insertMessage|createStructuredPointer|mailboxHandle|coordinatorHandle' src/main -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- coordinator-runs schema and stores ---'
rg -n -C5 'CREATE TABLE.*coordinator_runs|coordinator_runs|coordinator_handle' src/main/runtime/orchestration/db -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- migration orchestration ---'
cat -n src/main/runtime/orchestration/db/schema/migrate.ts | sed -n '1,100p'Repository: stablyai/orca Length of output: 45667 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- deliveries mailbox_handle ---'
rg -n -C5 '\bmailbox_handle\b' src/main/runtime/orchestration/db src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- dispatch and task handle declarations/writes ---'
rg -n -C4 'assignee_handle|creator_handle|created_by_terminal_handle|terminal_handle|from_handle|to_handle' src/main/runtime/orchestration/db/schema src/main/runtime/orchestration/db/dispatch src/main/runtime/orchestration/db/tasks src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts' | head -n 500
printf '%s\n' '--- gate/question persistence ---'
rg -n -C5 'question_threads|decision_gate|requester|caller|asker_handle|created_by_terminal_handle' src/main/runtime/orchestration/db src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts' | head -n 500Repository: stablyai/orca Length of output: 42725 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- mailbox delivery API and callers ---'
sed -n '1,125p' src/main/runtime/orchestration/db/messages/role-mailbox-delivery.ts
rg -n -C6 'enqueue|create|deliver|mailboxHandle|mailbox_handle' src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts' | rg -C3 'delivery|mailboxHandle|mailbox_handle|enqueue|create'
printf '%s\n' '--- task and gate write boundaries ---'
rg -n -C8 'INSERT INTO tasks|created_by_terminal_handle|INSERT INTO question_threads|asker_handle|createDecision|decision_gates' src/main/runtime/orchestration/db src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts'Repository: stablyai/orca Length of output: 45663 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- exact delivery callers ---'
rg -n -C8 'getOrCreateMailboxDelivery|requireMailboxConsumer' src/main -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- mailbox consumer implementation ---'
cat -n src/main/runtime/orchestration/db/messages/mailbox-consumer.ts
printf '%s\n' '--- task creation inputs ---'
rg -n -C10 'createTask\(|createdByTerminalHandle|created_by_terminal_handle' src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- gate creation implementation ---'
rg -n -C12 'export function createGate|function createGate|INSERT INTO decision_gates' src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts'Repository: stablyai/orca Length of output: 41471 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- question-thread backfill call and ordering ---'
rg -n -C8 'backfillLegacyQuestionThreads|asker_handle' src/main/runtime/orchestration/db/schema src/main/runtime/orchestration/db -g '*.ts' -g '!**/*.test.ts'
printf '%s\n' '--- question-thread consumers and writers ---'
rg -n -C8 'asker_handle|question_threads' src/main/runtime/orchestration/db src/main/runtime/rpc src/main/runtime/orchestration -g '*.ts' -g '!**/*.test.ts' | head -n 700
printf '%s\n' '--- migration calls around question backfill and v43 ---'
rg -n -C10 'backfillLegacy|migrateV20|migrateV43|migrateV41' src/main/runtime/orchestration/db/schema -g '*.ts'Repository: stablyai/orca Length of output: 41987 Migrate legacy addresses in
Suggested fix ['messages', 'from_handle'],
['messages', 'to_handle'],
- ['coordinator_runs', 'coordinator_handle']
+ ['coordinator_runs', 'coordinator_handle'],
+ ['question_threads', 'asker_handle']
] as const🧰 Tools🪛 OpenGrep (1.30.0)[ERROR] 35-35: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead. (coderabbit.command-injection.exec-js) [ERROR] 38-41: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead. (coderabbit.command-injection.exec-js) |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.