checkpoint: unify committed writes behind Store.Write(ctx, WriteRequest) · Entire
Checkpoint: Unify Committed Writes Behind Store.Write(ctx, WriteRequest)
6e78390→main·
Soph·4w ago·10 files·+211 added/-17 removed
Replace the four-method committed writer surface (WriteCommitted / UpdateCommitted / UpdateSummary / UpdateCheckpointSummary) with a single Store.Write(ctx, WriteRequest) entry point and a sealed request union:
- WriteSession -> create/replace a session (former WriteCommitted)
- BackfillTranscript -> stop-time transcript finalize (former UpdateCommitted)
- BackfillSummary -> async summary backfill (former UpdateSummary)
- BackfillAttribution -> root combined attribution (former UpdateCheckpointSummary)
WriteSession/BackfillTranscript are defined types over the existing option structs, so the migration is zero payload churn (T(opts) round-trips) and call sites stay flat (checkpoint.WriteSession{...}). Each request carries exactly its own fields, so the shared-option-bag footgun (an attribution option silently no-oping on a session write) is impossible by construction.
A single Write is also the natural mirror/fan-out target: a multi-backend store just forwards the request value. The CommittedStore interface now embeds Writer; the concrete per-operation methods remain on GitStore as the implementation Write dispatches to (and as the direct entry point for the git-store unit tests). Unknown request types surface an error rather than being silently ignored.
Production call sites migrated; committed_write_test.go covers every dispatch case plus the unsupported-request and not-found paths.
Sessions
957b03f1f773View transcript
Changes
10
- cmd/entire/cli
- Mattach.go +1/-1
- benchutil
- Mbenchutil.go +1/-1
- checkpoint
- Mcommitted_reader_resolve.go +4/-9
- Acommitted_write.go +74
- Acommitted_write_test.go +122
- Mstore.go +3
- M explain.go +2/-2
- M explain_test.go +1/-1
- strategy
- Mmanual_commit_condensation.go +1/-1
- Mmanual_commit_hooks.go +2/-2
336 unmodified lines
337
338
339
340
340
341
342
343
336 unmodified lines
writeOpts.HasReview = true
}
if err := store.WriteCommitted(ctx, writeOpts); err != nil {
if err := store.Write(ctx, cpkg.WriteSession(writeOpts)); err != nil {
return fmt.Errorf("failed to write checkpoint: %w", err)
}
Code blocks:
Mcmd/entire/cli/attach.go +1/-1
197 unmodified lines
248
249
250
...
CommittedWriter
// CommittedWriter provides write access to committed checkpoint data.
type CommittedWriter interface {
WriteCommitted(ctx context.Context, opts WriteCommittedOptions) error
UpdateCommitted(ctx context.Context, opts UpdateCommittedOptions) error
UpdateSummary(ctx context.Context, checkpointID id.CheckpointID, summary *Summary) error
UpdateCheckpointSummary(ctx context.Context, checkpointID id.CheckpointID, combinedAttribution *InitialAttribution) error
}
CommittedStore
// CommittedStore provides the production committed checkpoint storage surface.
// Writes go through the unified Writer.Write(ctx, WriteRequest); the concrete
// per-operation methods (WriteCommitted/UpdateCommitted/...) remain on GitStore
// as the implementation Write dispatches to.
type CommittedStore interface {
CommittedListReader
ReadSessionMetadataAndPrompts(ctx context.Context, checkpointID id.CheckpointID, sessionIndex int) (*SessionContent, error)
CommittedWriter
Writer
}
Writer
// Writer is the committed-store write surface: a single Write that accepts any
// WriteRequest. It is the natural type for mirror fan-out.
type Writer interface {
Write(ctx context.Context, req WriteRequest) error
}
Dispatch Method
// Write dispatches a committed write request to the matching git operation.
// Unknown request types are a programmer error, surfaced rather than ignored.
func (s *GitStore) Write(ctx context.Context, req WriteRequest) error {
switch r := req.(type) {
case WriteSession:
return s.WriteCommitted(ctx, WriteCommittedOptions(r))
case BackfillTranscript:
return s.UpdateCommitted(ctx, UpdateCommittedOptions(r))
case BackfillSummary:
return s.UpdateSummary(ctx, r.CheckpointID, r.Summary)
case BackfillAttribution:
return s.UpdateCheckpointSummary(ctx, r.CheckpointID, r.Attribution)
default:
return fmt.Errorf("checkpoint: unsupported write request %T", req)
}
}
Tests
// TestWrite_DispatchesEachRequest verifies that Store.Write routes each request
// type to the corresponding git operation, observing the effect of each.
func TestWrite_DispatchesEachRequest(t *testing.T) {
...
// Further test implementation
}
This documentation outlines the restructuring of the writing operations to streamline the process into fewer methods and provide clarity in the code flow, ensuring robustness and maintainability.