Repository navigation
feat(importers): import opencode sessions - #345
Conversation
upsetbit
left a comment
There was a problem hiding this comment.
Review by GPT-6.2-Astra (gpt-6.2-astra, reasoning effort max) via CODEX_HOME=~/.codex-mz. Thread 01a22d52-7992-7d72-98de-69bc675a4657. Reviewed 776f5435.
The importer uses the source session IDs, gives v2 rows precedence, maps cache and reasoning tokens correctly, and keeps credential-table rows out of the JSONL accepted by the server. Sync can leave session metadata stale, drop measured requests, and underprice long prompts.
OC-01 major internal/importers/opencode/project.go
projectionLines omits parent_id, directory, model, time_created, and time_updated. Changing only one of those fields leaves the JSONL hash unchanged, so LastHash skips the local update. Even after --overwrite refreshes the local row, the server sees the same raw hash and skips the push. Include the source session metadata in the hashed JSONL.
OC-02 major internal/importers/opencode/project.go
The session-wide choice drops measured usage when one assistant message has a step-finish and another has only message-level tokens. With zero session-row counters, the importer labels the subtotal complete. If the step reports zero and the other message reports positive tokens, it skips the entire session as no_usage. Choose the usage source per assistant message so each measured inference counts once.
OC-03 major internal/importers/opencode/project.go
requestFrom leaves PromptTokens unset even when the cache-inclusive prompt length is known. The pricing engine uses that field to select the long-context rate. An OpenCode gemini-2.5-pro request with 200,001 input tokens receives the short-context rate. Populate PromptTokens from the cache-inclusive input when the breakdown is available.
OC-04 major internal/importers/opencode/parse.go
All v2 messages and parts are already in memory when loadLayout loads the entire legacy history. The duplicate-ID check runs afterward. A migrated database with a large message and part payload in each layout retains both before the first session is written. Filter shadowed legacy IDs in SQL and process one session or a bounded batch at a time.
OC-05 major internal/importers/opencode/parse.go
Dropping a malformed v2 message also removes its ID from the index used by loadParts. Valid text and tool-result parts attached to that message then disappear from both the raw JSONL and the projected turns. The v2 row still supplies the message ID, type, sequence, and timestamp. Retain that envelope so intact parts survive the malformed payload.
OC-06 minor internal/importers/opencode/import_db.go
The marker gives every historical database hash its own state_seen entry. After importing a database, changing a message, and restoring the original database from backup, the old marker short-circuits the import and leaves the newer message in the store. Key the marker by a stable source database identity and compare its most recently imported hash.
OC-07 minor internal/importers/opencode/project.go
Message timestamps override populated time_created and time_updated. A session created May 1 that contains an April 30 message is filed under April. The canonical mapping gives the session-row timestamps precedence. Use the earliest or latest message time only when the corresponding row timestamp is missing.
OC-08 minor internal/importers/opencode/project.go
When the session row has no model, every message is inspected. A user or model-switched record carrying a model can set Session.Model before the first assistant response supplies the model actually used. Restrict this fallback to assistant records and their model.id or modelID fields.
OC-09 minor internal/importers/opencode/import_db.go
If only a credential or event row changes, the database hash changes while every session projection still matches. With zero session writes and zero policy skips, the result is Skipped: false, so prosa sync --json reports an import. Return a skipped result when the database scan writes no sessions.
|
Addressed the Astra findings in a51b125.
|
A compaction record is a summarization call with its own model and tokens, and the session-row counters include it. Each compaction now yields a request, so a session with one can reach complete coverage and a zero session row keeps its compaction tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review follow-ups in 0fe0d7f..6fbb13f.
|
Summary
opencode.db(andopencode-<channel>.db) into the CLI. Each session is a JSONL projection, so the database — which also holds credentials — is not copied into the raw store.opencodeon session push and store the raw object as.jsonl. The panel filter lists the agent as OpenCode.Test plan
go test ./internal/importers/opencode/ ./internal/paths/ ./internal/cli/ -count=1go test ./internal/server/handlers/ -count=1 -run 'TestValidatePushedAgent|TestRawKeyOpenCode'go test ./internal/panel/ -count=1 -run 'TestDisplayAgent|TestSessionsFeedRowSwapsSidePanel'~/.local/share/opencode/opencode.dbinto a temporaryPROSA_HOMEand checked that each session's raw artifact is a.jsonl