Repository navigation
amikalog: store one JSONL file per session and parallelize sync - #248
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b20c00d86f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| units = append(units, uploadUnit{ | ||
| relKey: relKey, | ||
| objectKey: strings.ToLower(path.Join(resolveRepoSegmentJSONL(filePath), relKey)), |
There was a problem hiding this comment.
Hold the session lock while choosing the repo prefix
When beta:push runs concurrently with the first hook for a session, writeEvent creates the .jsonl file before writing the first line while holding the same lock, but this repo-prefix resolution reads the file without that lock. In that window resolveRepoSegmentJSONL sees an empty/partial file, returns unknown-repo, then snapshotFile waits for the lock and uploads the completed event under the wrong object key; if the session never grows again, it remains misfiled even though the event contains git.repo_root.
Useful? React with 👍 / 👎.
| enc := json.NewEncoder(f) | ||
| enc.SetIndent("", " ") | ||
| if encErr := enc.Encode(ev); encErr != nil { | ||
| if _, err := f.Write(line); err != nil { |
There was a problem hiding this comment.
Avoid leaving partial JSONL records on failed appends
If this append is short and returns an error (for example, a disk-full or I/O error after some bytes are written), the partial JSON bytes remain in the session .jsonl. The next hook appends after those bytes and countLines ignores the unterminated record, so the session file can become permanently unparsable and sequence numbers can repeat; the previous temp-file-and-rename scheme did not publish failed writes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b97cfa104
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if recorded, ok := manifest.Uploaded[u.relKey]; ok && (recorded == legacyUploaded || recorded == u.size) { | ||
| report.Skipped++ | ||
| continue |
There was a problem hiding this comment.
Recheck JSONL size after locking the file
When a session JSONL file was previously uploaded at size N, collectUploadUnits records its size before any session lock is held; if a hook appends a new event after that stat but before this skip check, u.size still equals the manifest value and this push skips the file entirely. In that concurrent-hook scenario the just-captured event is not uploaded during the beta:push run even though it exists before the command exits, because no locked snapshot is taken for skipped files.
Useful? React with 👍 / 👎.
| scanner := bufio.NewScanner(bytes.NewReader(data)) | ||
| // Allow large single-event lines (big hook payloads) past bufio's default | ||
| // 64 KiB token cap. | ||
| scanner.Buffer(make([]byte, 0, 64*1024), 16*1024*1024) |
There was a problem hiding this comment.
Avoid capping repo detection at 16 MiB lines
For a session whose JSONL event line exceeds 16 MiB, bufio.Scanner returns ErrTooLong before yielding that line, and this function ignores the scanner error and falls back to unknown-repo. Large hook payloads are stored verbatim in each event, so a large first event from a real repository will be uploaded under the wrong bucket prefix even though its git.repo_root is present in the bytes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48778e5293
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return fmt.Errorf("closing event %s: %w", finalPath, closeErr) | ||
| start := info.Size() | ||
|
|
||
| n, writeErr := f.Write(line) |
There was a problem hiding this comment.
Avoid publishing partial records on mid-write termination
If the hook process is killed or the machine loses power while this Write is in progress, the newly created .jsonl session file can be left with a partial final record because the rollback path never runs. The next capture counts only newline-terminated records and appends after those partial bytes, which can corrupt the JSONL stream and reuse a Seq; the previous temp-file-and-rename layout did not expose a partially written event at the final path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8dd3b44fe9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if err != nil { | ||
| return nil, 0, false, fmt.Errorf("reading %s: %w", u.relKey, err) | ||
| } | ||
| return completeRecords(b), int64(len(b)), false, nil |
There was a problem hiding this comment.
Record only uploaded JSONL bytes as the fingerprint
When a session file has a crash-left partial tail and beta:push runs before the next hook, this uploads only completeRecords(b) but records len(b) including the dropped tail. If the next capture heals that tail and appends a real event whose size brings the file back to the recorded length, the unchanged(info.Size()) check skips the file even though that new complete event was never uploaded; if the session does not grow again, the event remains missing from the org bucket.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ec5773c1b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return | ||
| } | ||
| objectKey := u.objectKeyFor(payload) | ||
| if err := up.Upload(objectKey, payload); err != nil { |
There was a problem hiding this comment.
Serialize pushes before overwriting session objects
When two beta:push processes overlap while a JSONL session grows, an older snapshot can be uploaded after a newer one to the same object key; because the uploader uses upsert semantics, that late older PUT overwrites the bucket object with fewer records. If the newer process then saves a manifest entry for the larger local size after the older upload, later pushes will see the size as already uploaded and skip the file, leaving the remote session missing the appended events until the file grows again. The old per-event layout did not have this stale-overwrite path because each object was immutable, so the new session-file upload needs a cross-process push lock or another monotonic write guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ec2c6775b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if repoSeg == "" { | ||
| repoSeg = repoSegmentFromJSONL(data) | ||
| } |
There was a problem hiding this comment.
Keep a session's upload key stable after first push
If a session is first pushed while its complete records have no git.repo_root, this computes the object key with the unknown-repo prefix and records only the relative path in the manifest; when a later event in the same JSONL file includes git context, the next push re-uploads the entire session under the repo prefix instead. Because the old unknown-repo/...jsonl object is never deleted and now contains a prefix of the same session, beta:fetch and downstream consumers will see duplicate events for sessions whose repo context appears after an earlier push. Consider persisting the chosen object key/repo prefix per session or otherwise preventing the prefix from changing after a successful upload.
Useful? React with 👍 / 👎.
Replace the one-file-per-event layout with a per-session append-only JSONL file, and upload/download in bounded parallel pools instead of serially — far fewer files and round-trips. Capture heals a crash-left partial tail before appending. Push runs under a cross-process lock, snapshots each session under the per-source lock, trims to the last complete record, fingerprints by uploaded-bytes size so only grown sessions re-upload (idempotent), and pins each session's object key so its prefix never changes after the first upload. Legacy event_*.json files still upload for back-compat.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
amikalog 0.2.0 changelog (amikalog@v0.1.0..amikalog@v0.2.0): - amikalog: store one JSONL file per session and parallelize sync (#248) Capture now appends one compact JSON line per event to a per-session file under the existing cross-process lock. Push uploads each changed session file in a bounded parallel pool, tracking uploaded byte size so only sessions that grew are re-sent. Fetch downloads objects in a bounded parallel pool. Backward compatible with legacy per-event files.
Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 5.0.0 to 6.1.0. ## Release notes Sourced from pnpm/action-setup's releases. ### v6.1.0 ### What's Changed - feat: support pnpm v12 by `@zkochan` in pnpm/action-setup#288 Full Changelog: pnpm/action-setup@v6.0.10...v6.1.0 ### v6.0.10 ### What's Changed - docs(README): point users to the successor pnpm/setup action by `@BlackHole1` in pnpm/action-setup#282 - refactor: introduce restore keys for cache by `@SukkaW` in pnpm/action-setup#280 - ci: use pnpm 11 for `pr-check` by `@jamietanna` in pnpm/action-setup#284 - fix: update pnpm to v11.19.0 by `@jamietanna` in pnpm/action-setup#283 - docs: update README to include devEngines.packageManager by `@nemchik` in pnpm/action-setup#273 ### New Contributors - `@jamietanna` made their first contribution in pnpm/action-setup#284 - `@nemchik` made their first contribution in pnpm/action-setup#273 Full Changelog: pnpm/action-setup@v6...v6.0.10 ### v6.0.9 ### What's Changed - fix: update pnpm to v11.7.0 by `@zkochan` in pnpm/action-setup#267 Full Changelog: pnpm/action-setup@v6...v6.0.9 ### v6.0.8 ### What's Changed - docs(README): fix `cache_dependency_path` type by `@haines` in pnpm/action-setup#257 - fix: drop patchPnpmEnv so standalone+self-update works on Windows by `@zkochan` in pnpm/action-setup#258 - fix: update pnpm to 11.1.1 by `@mungodewar` in pnpm/action-setup#248 ### New Contributors - `@mungodewar` made their first contribution in pnpm/action-setup#248 Full Changelog: pnpm/action-setup@v6.0.7...v6.0.8 ### v6.0.7 ### What's Changed - fix: honor devEngines.packageManager.onFail=error (#252) by `@zkochan` in pnpm/action-setup#254 - fix: restore inputs from state in post by `@haines` in pnpm/action-setup#255 - fix: self-update bootstrap to packageManager-pinned version (#233) by `@zkochan` in pnpm/action-setup#256 ### New Contributors - `@haines` made their first contribution in pnpm/action-setup#255 Full Changelog: pnpm/action-setup@v6.0.6...v6.0.7 ... (truncated) ## Commits - `ea17c68` feat: support pnpm v12 (#288) - `0977fd9` docs: Update README to include devEngines.packageManager (#273) - `48261ac` fix: update pnpm to v11.19.0 (#283) - `75677f7` ci: use pnpm 11 for `pr-check` (#284) - `769ae71` refactor: introduce restore keys for cache (#280) - `6fed91f` docs(README): point users to the successor pnpm/setup action (#282) - `0ebf471` fix: update pnpm to v11.7.0 (#267) - `0e279bb` fix: update pnpm to 11.1.1 (#248) - `3e83581` fix: drop patchPnpmEnv so standalone+self-update works on Windows (#258) - `551b42e` docs(README): fix `cache_dependency_path` type (#257) - Additional commits viewable in compare view
Capture appended one JSON file per hook event, and beta:push/beta:fetch processed objects serially, so a single session produced hundreds of tiny files and hundreds of sequential signed-URL round-trips each way.
Capture now appends one compact JSON line per event to a per-session file (/events//sessions/_.jsonl) under the existing cross-process lock. Push uploads each changed session file in a bounded parallel pool, tracking each file's uploaded byte size so only sessions that grew new events are re-sent (idempotent upsert); session files are read under the lock so a half-written final line is never uploaded. Fetch downloads each page's objects in a bounded parallel pool, still page-by-page to keep signed URLs fresh.
Backward compatible: legacy per-event event_*.json files are still uploaded, and a tolerant manifest unmarshal maps old timestamp-string entries to "already uploaded" so the format change does not re-push existing history.