Skip to content

Archiving: finish all traffic fetches before writing a repository #103

Open

Description

@HafidIdrissi

Why

archive_repo currently writes views before fetching clones and snapshots, so a later API failure can leave an incomplete refresh.

Scope and acceptance criteria

Separate collection/preparation from publication for one repository: fetch all four endpoint payloads successfully before its first archive write. Preserve continuation to other repositories. This prevents writes on fetch failure, not a claim of an atomic six-file transaction; #14 still owns per-file atomic writes.

Starting points

  • src/traffic_archive/cli.py archive_repo
  • tests/test_cli.py

Validation

Inject a failure at each endpoint and compare all existing file bytes/directory entries; assert no new repository directory on failed collection and unchanged successful output.

For Python changes, run the focused tests and python -m pytest with the same environment. Use synthetic fixtures, mocked network calls and temporary files; preserve standard-library-only runtime dependencies and supported Python versions. Distinguish actual local results from CI and untested steps.

Contributing

Difficulty: intermediate. Read CONTRIBUTING.md, post a short plan and coordinate assignment before substantial work. Keep one problem per PR. Proposed paths are new files. Resolve interfaces/dependencies with cited issues before implementation; do not duplicate their scope. Never commit credentials or live traffic data.

Activity

  1. rajshadow commented on Oct 22, 2026

    @rajshadow

    Hello there, I would be interested in claiming this. Here is my understanding of the issue and the proposed fix + validation. Open to adjusting the plan before implementation.

    Current flow:

    Fetch views → save views
    Fetch clones → save clones
    Fetch referrers → save referrers
    Fetch paths → save paths
    

    The issue is that if say, views and clones succeed but referrers call fails, we have an intermediate state w.r.t freshness of the various histories. The process would mark the repo as skipped while the archive has been partly updated.

    Success criteria:

    Situation Success criterion
    Any of the four fetches fails Existing archive file bytes and directory entries remain unchanged.
    Collection fails for a repo with no archive yet No new archive is created.
    One repo encounters a handled API error Processing continues to the next repository
    All four fetches succeed The existing merge rules, output formats and summary values are preserved.

    Proposal :

    Reorganize the flow so that all the reads are attempted first, and upon successful fetch for all, perform the necessary metric level merge and save:

    Fetch views → fetch clones → fetch referrers → fetch paths
                                ↓
                      Then merge and save
    

    Test plan:

    Test Assert
    Fetch fails with an existing archive—test each endpoint All file bytes and directory entries remain unchanged.
    Fetch fails with no existing archive—test each endpoint No repository directory is created.
    First repository’s fetch fails; second succeeds—test each endpoint Second repository completes; summary and exit code remain correct.
    All fetches succeed The expected six files, contents, formats and totals are produced.

    Out of scope:

    • A failure during writing may leave some archive files updated and others unchanged. Per-file atomic writes (Write archive JSON and CSV files atomically #14) would prevent partially written individual files, but would not make the six-file archive update atomic.
  2. HafidIdrissi commented on Oct 22, 2026

    @HafidIdrissi
    OwnerAuthor

    Thanks @rajshadow — assigned to you. Your analysis, proposed ordering and test matrix match #103; no conflicting implementation is currently open. All four traffic fetches must succeed before the first archive write or creation of a new repository archive directory. If any fetch raises the handled API error, existing files/directory entries must remain byte-for-byte unchanged, an absent archive must remain absent, and the CLI must continue to the next repository with the existing summary/exit behavior.

    Please preserve successful merge rules, the six output files, formats and totals. As you correctly noted, this is protection against collection failure, not an atomic six-file publication guarantee; write-failure transactions and #14's per-file atomicity remain separate. #125 is reviewed/approved but not merged yet and validates response containers in api.py; keep that scope separate and update your branch when it lands. Existing CLI changes in #77 also remain separate.

    Use synthetic rows, mocked failures at each of the four endpoints, disposable existing archives and absent-output cases. Verify a later repository still succeeds and compare successful output against the existing behavior. Run focused CLI tests and python -m pytest with the same environment; retain supported Python versions and standard-library-only runtime dependencies. Report exact OS/Python, commands/results and skipped checks separately from CI. Open one focused PR with Closes #103.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions