3
43
Fork
You've already forked opencode.el
16

fix nil and :null handling in API responses #2

Manually merged
sczi merged 1 commit from avph/opencode.el:fix-nil-handling into main 2026年01月15日 17:35:13 +01:00
Contributor
Copy link
  • opencode--time-ago now returns nil for missing timestamps
  • add opencode--format-time-ago helper for safe formatting
  • handle :null (JSON null) in session summary fields
  • check for nil directory before file-exists-p in Branch column
  • filter out projects with nil worktree
- opencode--time-ago now returns nil for missing timestamps - add opencode--format-time-ago helper for safe formatting - handle :null (JSON null) in session summary fields - check for nil directory before file-exists-p in Branch column - filter out projects with nil worktree
- opencode--time-ago now returns nil for missing timestamps
- add opencode--format-time-ago helper for safe formatting
- handle :null (JSON null) in session summary fields
- check for nil directory before file-exists-p in Branch column
- filter out projects with nil worktree
Owner
Copy link

Looks good but is it needed to handle these cases? AFAIK in emacs default-directory will always be set. for the API responses I haven't run into these cases, and looking at packages/sdk/js/src/gen/types.gen.ts worktree in the project API response, and directory in the session API response are guaranteed to be present. summary is optional in the session info, but if it's present then files, deletions, and additions are guaranteed to be present, and if it's not present the existing (null .files) check will handle it

Looks good but is it needed to handle these cases? AFAIK in emacs `default-directory` will always be set. for the API responses I haven't run into these cases, and looking at `packages/sdk/js/src/gen/types.gen.ts` worktree in the project API response, and directory in the session API response are guaranteed to be present. summary is optional in the session info, but if it's present then files, deletions, and additions are guaranteed to be present, and if it's not present the existing `(null .files)` check will handle it
Author
Contributor
Copy link

Hi thanks for reviewing. I've used opencode for a long time and I think there is legacy data in the sessions as well as edge cases.

  • Older sessions (pre-0.13.x) don't have a directory field at all. From my /session response:
    ((id . "ses_7a07d100fffejXf8epJhA47flz") (version . "0.3.58")
    (title . "Adding mbox size handling across mailbox implementations")
    (time (created . 1753949073392) (updated . 1753953708805)))
    No directory field - calling (file-exists-p nil) throws wrong-type-argument stringp nil.

  • Some sessions have summary present but with JSON null values that json-parse-buffer returns as :null:
    (summary (additions . :null) (deletions . :null) (files . 1078))
    Since :null is truthy in Emacs Lisp, (or :null 0) returns :null, not 0, causing (format "%d" :null) to fail.

  • Some sessions/projects lack time.updated, causing (/ nil 1000) to fail in opencode--time-ago.

Hi thanks for reviewing. I've used opencode for a long time and I think there is legacy data in the sessions as well as edge cases. - Older sessions (pre-0.13.x) don't have a directory field at all. From my /session response: ((id . "ses_7a07d100fffejXf8epJhA47flz") (version . "0.3.58") (title . "Adding mbox size handling across mailbox implementations") (time (created . 1753949073392) (updated . 1753953708805))) No directory field - calling (file-exists-p nil) throws wrong-type-argument stringp nil. - Some sessions have summary present but with JSON null values that json-parse-buffer returns as :null: (summary (additions . :null) (deletions . :null) (files . 1078)) Since :null is truthy in Emacs Lisp, (or :null 0) returns :null, not 0, causing (format "%d" :null) to fail. - Some sessions/projects lack time.updated, causing (/ nil 1000) to fail in opencode--time-ago.
sczi manually merged commit cdb62730d9 into main 2026年01月15日 17:35:13 +01:00
Owner
Copy link

Ah, yea I just started using opencode about a month ago, but I also use it in a temporary sandbox as described in the security section of the readme, so I don't store old session history.

I just factored out a opencode--json-falsy utility function cause I'm pretty OCD about repeating code, and we do the null or :null checks twice already and I assume might need to add in other spots later.

Ah, yea I just started using opencode about a month ago, but I also use it in a temporary sandbox as described in the security section of the readme, so I don't store old session history. I just factored out a `opencode--json-falsy` utility function cause I'm pretty OCD about repeating code, and we do the null or :null checks twice already and I assume might need to add in other spots later.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sczi/opencode.el!2
Reference in a new issue
sczi/opencode.el
No description provided.
Delete branch "avph/opencode.el:fix-nil-handling"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?